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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.oper.TbGropMenuAthr;
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("TbGropMenuAthrDto(그룹-메뉴권한)")
public class TbGropMenuAthrDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("운영시스템메뉴ID")  // N VARCHAR(30)
    @JsonProperty("opersyst_menu_id")
    private String operSystMenuId;

    @ApiModelProperty("권한 여부")  // Y CHAR(1)
    @JsonProperty("athr_yn")
    private String athrYn;

    // Code Description Field
    @ApiModelProperty("권한 여부 설명")
    @JsonProperty("athr_yn_desc")    // ATHR_YN
    private String athrDesc;

    @ApiModelProperty("그룹명")
    @JsonProperty("grop_nm")
    private String gropNm;
    @ApiModelProperty("운영시스템")
    @JsonProperty("opersyst_id")
    private String operSystId;       //	N	VARCHAR2(30)	Y			운영시스템ID
    @ApiModelProperty("운영시스템명")
    @JsonProperty("opersyst_nm")
    private String operSystNm;
    @ApiModelProperty("운영시스템메뉴명")
    @JsonProperty("opersyst_menu_nm")
    private String operSystMenuNm;

    public void updateMenuAuth(TbGropMenuAthr entity) {
        this.athrYn = entity.getAthrYn();
        this.athrDesc = this.athrYn.equals("Y") ? "[Y] 권한있음" : "[N] 권한없음";
    }

    @ApiModel("TbGropMenuAthrUpdReq(그룹-메뉴권한 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbGropMenuAthrUpdReq {

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

        @ApiModelProperty("운영시스템메뉴ID, Nullable = N, VARCHAR(30)")  // N VARCHAR(30)
        @JsonProperty("opersyst_menu_id")
        @Size(min=1, max=30)
        private String operSystMenuId;

        @ApiModelProperty("권한 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("athr_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String athrYn;


        @Builder
        public TbGropMenuAthrUpdReq(String grop_id, String opersyst_menu_id, String athr_yn, String last_crct_dt, String last_crpr_nmbr, String frst_regr_nmbr, String frst_rgst_dt) {
            this.gropId = grop_id;
            this.operSystMenuId = opersyst_menu_id;
            this.athrYn = athr_yn;
        }

        public TbGropMenuAthr toEntity() {
            return TbGropMenuAthr.builder()
                    .gropId(this.gropId)
                    .operSystMenuId(this.operSystMenuId)
                    .athrYn(this.athrYn)
                    .build();
        }

    }

}
