package com.icomsys.main_vm.db.jpa.entity.system;

import com.icomsys.main_vm.db.jpa.entity.system.id.TbServiceAuthGroupId;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.time.LocalDateTime;

@Table(name = "TB_SERVICE_AUTH_GROUP")
@Entity
@Getter
@Setter
@NoArgsConstructor
@DynamicUpdate
public class TbServiceAuthGroup {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "AUTH_GROUP_SEQ", nullable = false)
    private Long authGroupSeq;
    @Column(name = "SERVICE_GROUP", nullable = false, length = 20)
    private String serviceGroup;
    @Column(name = "CUST_CODE", nullable = false, length = 20)
    private String custCode;
    @Column(name = "POLICY_GROUP_NAME", nullable = false, length = 50)
    private String policyGroupName;
    @Column(name = "POLICY_GROUP_DESC", nullable = true, length = 50)
    private String policyGroupDesc;
    @Column(name = "USE_YN", nullable = false, length = 1)
    private String useYn;
    @Column(name = "REGIST_ID", nullable = false, length = 20)
    private String registId;
    @Column(name = "REGIST_DATE", nullable = false)
    private LocalDateTime registDate;
    @Column(name = "UPDATE_ID", nullable = true, length = 20)
    private String updateId;
    @Column(name = "UPDATE_DATE", nullable = true)
    private LocalDateTime updateDate;

    @Builder
    public TbServiceAuthGroup(Long authGroupSeq, String serviceGroup, String custCode, String policyGroupName, String policyGroupDesc, String useYn, String registId, LocalDateTime registDate, String updateId, LocalDateTime updateDate) {
        this.authGroupSeq = authGroupSeq;
        this.serviceGroup = serviceGroup;
        this.custCode = custCode;
        this.policyGroupName = policyGroupName;
        this.policyGroupDesc = policyGroupDesc;
        this.useYn = useYn;
        this.registId = registId;
        this.registDate = registDate;
        this.updateId = updateId;
        this.updateDate = updateDate;
    }

    public TbServiceAuthGroup TbServiceAuthGroupModify(TbServiceAuthGroup dto){

        if(dto.authGroupSeq != null || !dto.authGroupSeq.equals("")){
            this.authGroupSeq = dto.authGroupSeq;
        }
        if(dto.policyGroupName != null || !dto.policyGroupName.equals("")){
            this.policyGroupName = dto.policyGroupName;
        }
        if(dto.policyGroupDesc != null || !dto.policyGroupDesc.equals("")){
            this.policyGroupDesc = dto.policyGroupDesc;
        }

        this.updateId = dto.updateId;
        this.updateDate = dto.updateDate;

        return this;
    }

}
