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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.oper.TbUserGropInfr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * 사용자그룹정보 DTO Class
 */
@Data
@Builder
@ApiModel("TbUsergropInfrDto(사용자그룹정보)")
public class TbUserGropInfrDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("그룹ID")  // N VARCHAR(30)
    @JsonProperty("grop_id")
    private String gropId;

    @ApiModelProperty("그룹명")  // Y VARCHAR(20)
    @JsonProperty("grop_nm")
    private String gropNm;

    @ApiModelProperty("설명")  // Y VARCHAR(100)
    @JsonProperty("expl")
    private String expl;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @JsonProperty("del_yn")
    private String delYn;

    // Code Description Field
    @ApiModelProperty("그룹 설명")
    @JsonProperty("grop_desc")
    private String gropDesc;

    @ApiModel("TbUsergropInfrUpdReq(사용자그룹정보 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbUserGropInfrUpdReq {

        @ApiModelProperty("그룹ID, Nullable = N, VARCHAR(30)")  // N VARCHAR(30)
        @JsonProperty("grop_id")
        @Size(min=1, max=30)
        private String gropId;

        @ApiModelProperty("그룹명, Nullable = Y, VARCHAR(20)")  // Y VARCHAR(20)
        @JsonProperty("grop_nm")
        @Size(min=1, max=20)
        private String gropNm;

        @ApiModelProperty("설명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("expl")
        @Size(min=1, max=100)
        private String expl;

        @ApiModelProperty("삭제 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("del_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String delYn;

        @Builder
        public TbUserGropInfrUpdReq(String grop_id, String grop_nm, String expl, String del_yn) {
            this.gropId = grop_id;
            this.gropNm = grop_nm;
            this.expl = expl;
            this.delYn = del_yn;
        }

        public TbUserGropInfr toEntity() {
            return TbUserGropInfr.builder()
                    .gropId(this.gropId)
                    .gropNm(this.gropNm)
                    .expl(this.expl)
                    .delYn(this.delYn)
                    .build();
        }

    }

}
