package com.its.api.its.model.entity.oper;

import com.its.api.its.model.dto.oper.TbUserGropInfrDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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_USERGROP_INFR")
public class TbUserGropInfr implements Serializable {
    private static final long serialVersionUID = 1L;

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

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

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

    @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)
                .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.delYn = req.getDelYn();
    }

}
