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

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

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

/**
 * CCTV 시나리오 DTO Class
 */
@Data
@Builder
@ApiModel("TbCctvScnrDto(CCTV 시나리오)")
public class TbCctvScnrDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("CCTV 관리 번호")  // N NUMBER(10)
    @JsonProperty("cctv_mngm_nmbr")
    private Long cctvMngmNmbr;

    @ApiModelProperty("시작 시각")  // N VARCHAR(6)
    @JsonProperty("strt_hms")
    private String strtHms;

    @ApiModelProperty("종료 시각")  // N VARCHAR(6)
    @JsonProperty("end_hms")
    private String endHms;

    @ApiModelProperty("프리셋 번호")  // Y VARCHAR(3)
    @JsonProperty("pset_nmbr")
    private String psetNmbr;

    @ApiModelProperty("시나리오수행시각, Nullable = Y, VARCHAR(14)")  // Y VARCHAR(14)
    @JsonProperty("ctrl_dt")
    private String ctrlDt;

    @ApiModelProperty("시나리오수행결과(Y:성공, N:실패), Nullable = Y, VARCHAR(3)")  // Y CHAR(1)
    @JsonProperty("ctrl_res_yn")
    private String ctrlResYn;

    // Code Description Field

    public TbCctvScnr toEntity() {
        TbCctvScnr entity = TbCctvScnr.builder()
                .cctvMngmNmbr(this.cctvMngmNmbr)
                .strtHms(this.strtHms)
                .endHms(this.endHms)
                .psetNmbr(this.psetNmbr)
                .build();

        entity.initEndHms();
        return entity;
    }

    @ApiModel("TbCctvScnrUpdReq(CCTV 시나리오 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbCctvScnrUpdReq {

        @ApiModelProperty("CCTV 관리 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("cctv_mngm_nmbr")
        @PositiveOrZero
        private Long cctvMngmNmbr;

        @ApiModelProperty("시작 시각, Nullable = N, VARCHAR(6)")  // N VARCHAR(6)
        @JsonProperty("strt_hms")
        @Size(min=1, max=6)
        private String strtHms;

        @ApiModelProperty("종료 시각, Nullable = N, VARCHAR(6)")  // N VARCHAR(6)
        @JsonProperty("end_hms")
        @Size(min=1, max=6)
        private String endHms;

        @ApiModelProperty("프리셋 번호, Nullable = Y, VARCHAR(3)")  // Y VARCHAR(3)
        @JsonProperty("pset_nmbr")
        @Size(min=1, max=3)
        private String psetNmbr;

        @Builder
        public TbCctvScnrUpdReq(Long cctv_mngm_nmbr, String strt_hms, String end_hms, String pset_nmbr) {
            this.cctvMngmNmbr = cctv_mngm_nmbr;
            this.strtHms = strt_hms;
            this.endHms = end_hms;
            this.psetNmbr = pset_nmbr;
        }

        public TbCctvScnr toEntity() {
            TbCctvScnr entity = TbCctvScnr.builder()
                    .cctvMngmNmbr(this.cctvMngmNmbr)
                    .strtHms(this.strtHms)
                    .endHms(this.endHms)
                    .psetNmbr(this.psetNmbr)
                    .build();

            entity.initEndHms();

            return entity;
        }

    }

}
