package com.kamco.cd.kamcoback.postgres.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;

@Getter
@Setter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(
    name = "tb_user",
    uniqueConstraints = {@UniqueConstraint(name = "ux_tb_user_user_id", columnNames = "user_id")})
public class UserEntity {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_user_id_gen")
  @SequenceGenerator(
      name = "tb_user_id_gen",
      sequenceName = "tb_user_user_uid_seq",
      allocationSize = 1)
  @Column(name = "user_uid", nullable = false)
  private Long id;

  @Size(max = 255)
  @NotNull
  @Column(name = "user_nm", nullable = false)
  private String userNm;

  @Size(max = 255)
  @NotNull
  @Column(name = "user_id", nullable = false)
  private String userId;

  @Size(max = 255)
  @NotNull
  @Column(name = "user_pw", nullable = false)
  private String userPw;

  @Size(max = 255)
  @NotNull
  @ColumnDefault("'ACTIVE'")
  @Column(name = "state", nullable = false)
  private String state = "ACTIVE";

  @Column(name = "date_withdrawal")
  private ZonedDateTime dateWithdrawal;

  @ColumnDefault("now()")
  @Column(name = "created_dttm")
  private ZonedDateTime createdDttm;

  @ColumnDefault("now()")
  @Column(name = "updated_dttm")
  private ZonedDateTime updatedDttm;

  @Column(name = "created_uid")
  private Long createdUid;

  @Column(name = "updated_uid")
  private Long updatedUid;

  @Size(max = 255)
  @Column(name = "user_email")
  private String userEmail;

  @Size(max = 20)
  @NotNull
  @Column(name = "user_auth", nullable = false, length = 20)
  private String userAuth;

  @Size(max = 255)
  @NotNull
  @Column(name = "emp_id", nullable = false)
  private String empId;

  public UserEntity(
      Long id,
      String userAuth,
      String userNm,
      String userId,
      String empId,
      String userEmail,
      String userPw) {
    this.id = id;
    this.userAuth = userAuth;
    this.userNm = userNm;
    this.userId = userId;
    this.empId = empId;
    this.userEmail = userEmail;
    this.userPw = userPw;
  }
}
