package com.pingcap.community.blogserver.entity;

import lombok.*;

import javax.persistence.*;

@Entity(name = "user_access_token")
@Table(name = "user_access_tokens")
@NamedEntityGraph(
    name = "withUser",
    attributeNodes = {
        @NamedAttributeNode(value = "user", subgraph = "withAuthorities"),
    },
    subgraphs = {
        @NamedSubgraph(
            name = "withAuthorities",
            attributeNodes = { @NamedAttributeNode("authorities"), @NamedAttributeNode("roles")}
        )
    }
)
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class UserAccessToken {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "id", nullable = false, updatable = false)
  private Long id;

  private String label;

  @Column(name = "access_token", unique = true)
  private String accessToken;

  @ManyToOne
  @JoinColumn(name = "user_id")
  private User user;

}
