package com.its.op.dto.its.facility;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.facility.TbFcltFailType;
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("TbFcltFailTypeDto(시설물 장애 유형)")
public class TbFcltFailTypeDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("장애유형")  // N VARCHAR2(7)
    @JsonProperty("fail_cd")
    private String failCd;

    @ApiModelProperty("장애유형 명")  // N VARCHAR2(30)
    @JsonProperty("fail_cd_nm")
    private String failCdNm;

    @ApiModelProperty("사용여부")  // Y CHAR(1)
    @JsonProperty("use_yn")
    private String useYn;

    // Code Description Field
    @ApiModelProperty("장애유형 설명")
    @JsonProperty("fail_desc")    // FAIL_CD
    private String failDesc;

    @ApiModelProperty("장애유형 명 설명")
    @JsonProperty("fail_desc_nm")    // FAIL_CD_NM
    private String failDescNm;

    @ApiModelProperty("사용여부 설명")
    @JsonProperty("use_desc")    // USE_YN
    private String useDesc;

    @ApiModel("TbFcltFailTypeUpdReq(시설물 장애 유형 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbFcltFailTypeUpdReq {

        @ApiModelProperty("장애유형, Nullable = N, VARCHAR2(7)")  // N VARCHAR2(7)
        @JsonProperty("fail_cd")
        @Size(min=1, max=7)
        private String failCd;

        @ApiModelProperty("장애유형 명, Nullable = N, VARCHAR2(30)")  // N VARCHAR2(30)
        @JsonProperty("fail_cd_nm")
        @Size(min=1, max=30)
        private String failCdNm;

        @ApiModelProperty("사용여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("use_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String useYn;

        @Builder
        public TbFcltFailTypeUpdReq(String fail_cd, String fail_cd_nm, String use_yn) {
            this.failCd = fail_cd;
            this.failCdNm = fail_cd_nm;
            this.useYn = use_yn;
        }

        public TbFcltFailType toEntity() {
            return TbFcltFailType.builder()
                    .failCd(this.failCd)
                    .failCdNm(this.failCdNm)
                    .useYn(this.useYn)
                    .build();
        }

    }

}
