package com.its.op.entity.its.oper;

import com.its.op.dto.its.oper.TbUserGropInfrDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * 사용자그룹정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("사용자그룹정보")
@Entity
@Table(name = "TB_USER_GROP_INFR")
public class TbUserGropInfr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("그룹ID")  // N VARCHAR2(30)
    @Id
    @Column(name = "GROP_ID", nullable = false, length = 7)
    private String gropId;

    @ApiModelProperty("그룹명")  // Y VARCHAR2(20)
    @Column(name = "GROP_NM", length = 30)
    private String gropNm;

    @ApiModelProperty("설명")  // Y VARCHAR2(100)
    @Column(name = "EXPL", length = 100)
    private String expl;

    @ApiModelProperty("")  // Y VARCHAR2(100)
    @Column(name = "OPER_SYST_IDS", length = 100)
    private String operSystIds;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
    private String delYn;

    public TbUserGropInfrDto toDto() {
        TbUserGropInfrDto dto = TbUserGropInfrDto.builder()
                .gropId(this.gropId)
                .gropNm(this.gropNm)
                .expl(this.expl)
                .operSystIds(this.operSystIds)
                .delYn(this.delYn)
                .build();

        dto.setGropDesc("[" + this.gropId + "] " + this.gropNm);
        return dto;
    }

    public TbUserGropInfr(String gropId) {
        this.gropId = gropId;
    }

    public void updateInfo(TbUserGropInfrDto.TbUserGropInfrUpdReq req) {
        this.gropNm = req.getGropNm();
        this.expl = req.getExpl();
        this.operSystIds = req.getOperSystIds();
        this.delYn = req.getDelYn();
    }

}
