package com.its.op.dto.its.oper;

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

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

    @ApiModelProperty("운영시스템ID")  // N VARCHAR2(30)
    @JsonProperty("oper_syst_id")
    private String operSystId;

    @ApiModelProperty("운영시스템메뉴ID")  // N VARCHAR2(100)
    @JsonProperty("menu_id")
    private String menuId;

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

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

    @ApiModelProperty("그룹명")
    @JsonProperty("grop_nm")
    private String gropNm;

    @ApiModelProperty("운영시스템명")
    @JsonProperty("oper_syst_nm")
    private String operSystNm;

    @ApiModelProperty("운영시스템메뉴명")
    @JsonProperty("oper_syst_menu_nm")
    private String operSystMenuNm;

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

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

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

        @ApiModelProperty("운영시스템ID, Nullable = N, VARCHAR2(30)")  // N VARCHAR2(30)
        @JsonProperty("oper_syst_id")
        @Size(min=1, max=30)
        private String operSystId;

        @ApiModelProperty("운영시스템메뉴ID, Nullable = N, VARCHAR2(100)")  // N VARCHAR2(100)
        @JsonProperty("menu_id")
        @Size(min=1, max=100)
        private String menuId;

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

        @Builder
        public TbUserGropMenuAthrUpdReq(String grop_id, String oper_syst_id, String menu_id, String athr_yn) {
            this.gropId = grop_id;
            this.operSystId = oper_syst_id;
            this.menuId = menu_id;
            this.athrYn = athr_yn;
        }

        public TbUserGropMenuAthr toEntity() {
            return TbUserGropMenuAthr.builder()
                    .gropId(this.gropId)
                    .operSystId(this.operSystId)
                    .menuId(this.menuId)
                    .athrYn(this.athrYn)
                    .build();
        }

    }

}
