package com.spring.domain.user.entity;

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.spring.common.jpa.AuditEntity;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "AGENT_USER")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AgentUser extends AuditEntity {
    
    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name="uuid2", strategy = "uuid2")
    @Column(name = "ID", nullable = false, columnDefinition = "BINARY(16)")
    private UUID id;

    @Column(name = "USER_ID", nullable = false, length = 50)
    private String userId;

    @Column(name = "PASSWORD", nullable = false, length = 128)
    private String password;

    @Column(name = "NAME", nullable = false, length = 50)
    private String name;

    @Column(name = "EMAIL", nullable = false, length = 100)
    private String email;

    @Column(name = "APPROVED", nullable = false)
    private boolean approved;

    @Enumerated(EnumType.STRING)
    @Column(name = "USER_ROLE", nullable = false, length = 50)
    private AgentUserRole userRole;

    @Builder
    public AgentUser(String userId, String password, String name, AgentUserRole userRole, String email, boolean approved, String createdBy, String modifiedBy) {
        this.userId = userId;
        this.password = password;
        this.name = name;
        this.userRole = userRole;
        this.email = email;
        this.approved = approved;
        this.createdBy = createdBy;
        this.modifiedBy = modifiedBy;
    }

    public void changePassword(String newPassword) {
        this.password = newPassword;
    }

    public void changeUserRole(AgentUserRole userRole) {
        this.userRole = userRole;
    }

    public void changeApproved(boolean approved) {
        this.approved = approved;
    }

}
