package com.its.op.entity.its.vms;

import com.its.op.dto.its.vms.TbVmsDsplSchDto;
import com.its.op.dto.its.vms.TbVmsDsplSchVmsListDto;
import com.its.utils.ItsUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.io.Serializable;

/**
 * VMS 교통 정보 표출 일정 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("VMS 표출 일정")
@Entity
@Table(name = "TB_VMS_DSPL_SCH")
@IdClass(TbVmsDsplSchKey.class)
public class TbVmsDsplSch implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("VMS 제어기 번호")  // N NUMBER(10)
    @Id
    @Column(name = "VMS_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long vmsCtlrNmbr;

    @ApiModelProperty("VMS 스케줄 유형(A:자동,F:고정,B:기본)")  // N VARCHAR2(5)
    @Id
    @Column(name = "VMS_SCH_TYPE", nullable = false, length = 5)
    private String vmsSchType;

    @ApiModelProperty("VMS 폼 스케쥴 유형(0:교통,1:돌발,2:공사행사,3:홍보,4:우회,5:정체,6:안전,7:동영상,8:스트리밍영상,9:대기환경,10:주차정보)")  // N NUMBER(3)
    @Id
    @Column(name = "VMS_SCH_FORM_TYPE", nullable = false, columnDefinition = "NUMBER", length = 3)
    private Integer vmsSchFormType;

    @ApiModelProperty("PHASE")  // N NUMBER(2)
    @Id
    @Column(name = "PHASE", nullable = false, columnDefinition = "NUMBER", length = 2)
    private Integer phase;

    @ApiModelProperty("VMS FORM ID")  // N NUMBER(5)
    @Column(name = "VMS_FORM_ID", nullable = false, columnDefinition = "NUMBER", length = 5)
    private Integer vmsFormId;

    @ApiModelProperty("표출시작시간")  // N VARCHAR2(14)
    @Column(name = "DSPL_STRT_HH", nullable = false, length = 14)
    private String dsplStrtHh;

    @ApiModelProperty("표출종료시간")  // N VARCHAR2(14)
    @Column(name = "DSPL_END_HH", nullable = false, length = 14)
    private String dsplEndHh;

    @ApiModelProperty("표출 시간")  // Y NUMBER(3)
    @Column(name = "DSPL_HH", columnDefinition = "NUMBER", length = 3)
    private Integer dsplHh;

    @ApiModelProperty("1단 VMS 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "FRST_VMS_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long frstVmsIfscId;

    @ApiModelProperty("2단 VMS 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "SECD_VMS_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long secdVmsIfscId;

    @ApiModelProperty("3단 VMS 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "THIR_VMS_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long thirVmsIfscId;

    @ApiModelProperty("4단 VMS 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "FOUR_VMS_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long fourVmsIfscId;

    @ApiModelProperty("1단 이미지 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "FRST_IMG_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long frstImgIfscId;

    @ApiModelProperty("2단 이미지 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "SECD_IMG_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long secdImgIfscId;

    @ApiModelProperty("3단 이미지 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "THIR_IMG_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long thirImgIfscId;

    @ApiModelProperty("4단 이미지 정보제공구간 ID")  // Y NUMBER(10)
    @Column(name = "FOUR_IMG_IFSC_ID", columnDefinition = "NUMBER", length = 10)
    private Long fourImgIfscId;

    @ApiModelProperty("동영상인 경우 동영상 파일 심벌 아이디")  // Y NUMBER(4)
    @Column(name = "SYMB_LIB_NMBR", columnDefinition = "NUMBER", length = 4)
    private Integer symbLibNmbr;

    @ApiModelProperty("스트리밍인경우 스트리밍 주소")  // Y VARCHAR2(60)
    @Column(name = "STRM_ADDR", length = 60)
    private String strmAddr;

    @ApiModelProperty("사용여부(Y:시용,N:사용안함)")  // Y CHAR(1)
    @Column(name = "USE_YN", columnDefinition = "CHAR", length = 1)
    private String useYn;

    @ApiModelProperty("일")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK1", length = 24)
    private String schWeek1;

    @ApiModelProperty("월")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK2", length = 24)
    private String schWeek2;

    @ApiModelProperty("화")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK3", length = 24)
    private String schWeek3;

    @ApiModelProperty("수")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK4", length = 24)
    private String schWeek4;

    @ApiModelProperty("목")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK5", length = 24)
    private String schWeek5;

    @ApiModelProperty("금")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK6", length = 24)
    private String schWeek6;

    @ApiModelProperty("토")  // Y VARCHAR2(24)
    @Column(name = "SCH_WEEK7", length = 24)
    private String schWeek7;

    @ApiModelProperty("정체폼 표출시 표출여부")  // Y CHAR(1)
    @Column(name = "DSPL_CNGS_YN", columnDefinition = "CHAR", length = 1)
    private String dsplCngsYn;

    @OneToOne
    @JoinColumn(insertable=false, updatable=false, name="VMS_FORM_ID", referencedColumnName = "VMS_FORM_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private TbVmsForm form;

    public void setEditInfo(TbVmsDsplSchDto.TbVmsDsplSchEditUpdReq dto) {
        this.dsplStrtHh = dto.getDsplStrtHh();
        this.dsplEndHh = dto.getDsplEndHh();
        this.dsplHh = dto.getDsplHh();
        this.useYn = dto.getUseYn();
    }

    public void setPhase(int phase) {
        this.phase = phase;
    }

    public TbVmsDsplSchDto toDto() {
        TbVmsDsplSchDto dto = TbVmsDsplSchDto.builder()
                .vmsCtlrNmbr(this.vmsCtlrNmbr)
                .vmsSchType(this.vmsSchType)
                .vmsSchFormType(this.vmsSchFormType)
                .phase(this.phase)
                .vmsFormId(this.vmsFormId)
                .dsplStrtHh(this.dsplStrtHh)
                .dsplEndHh(this.dsplEndHh)
                .dsplHh(this.dsplHh)
                .frstVmsIfscId(this.frstVmsIfscId)
                .secdVmsIfscId(this.secdVmsIfscId)
                .thirVmsIfscId(this.thirVmsIfscId)
                .fourVmsIfscId(this.fourVmsIfscId)
                .frstImgIfscId(this.frstImgIfscId)
                .secdImgIfscId(this.secdImgIfscId)
                .thirImgIfscId(this.thirImgIfscId)
                .fourImgIfscId(this.fourImgIfscId)
                .symbLibNmbr(this.symbLibNmbr)
                .strmAddr(this.strmAddr)
                .useYn(this.useYn)
                .schWeek1(this.schWeek1)
                .schWeek2(this.schWeek2)
                .schWeek3(this.schWeek3)
                .schWeek4(this.schWeek4)
                .schWeek5(this.schWeek5)
                .schWeek6(this.schWeek6)
                .schWeek7(this.schWeek7)
                .dsplCngsYn(this.dsplCngsYn)
                .build();

        if (this.form != null) {
            dto.setVmsFormTypeCd(this.form.getVmsFormTypeCd());
            dto.setVmsFormImag(ItsUtils.convertBmpToPng(this.form.getVmsFormImag()));
            dto.setImagFmt("png");
        }
        return dto;
    }
    public TbVmsDsplSchVmsListDto toVmsListDto() {
        return TbVmsDsplSchVmsListDto.builder()
                .vmsCtlrNmbr(this.vmsCtlrNmbr)
                .vmsSchType(this.vmsSchType)
                .vmsSchFormType(this.vmsSchFormType)
                .phase(this.phase)
                .vmsFormId(this.vmsFormId)
                .dsplHh(this.dsplHh)
                .dsplStrtHh(this.dsplStrtHh)
                .dsplEndHh(this.dsplEndHh)
                .useYn(this.useYn)
                .build();
    }

    public TbVmsDsplSch(Long vmsCtlrNmbr, String vmsSchType, Integer vmsSchFormType, Integer phase) {
        this.vmsCtlrNmbr = vmsCtlrNmbr;
        this.vmsSchType = vmsSchType;
        this.vmsSchFormType = vmsSchFormType;
        this.phase = phase;
    }

    public void updateInfo(TbVmsDsplSchDto.TbVmsDsplSchUpdReq req) {
        this.vmsFormId = req.getVmsFormId();
        this.dsplStrtHh = req.getDsplStrtHh();
        this.dsplEndHh = req.getDsplEndHh();
        this.dsplHh = req.getDsplHh();
        this.frstVmsIfscId = req.getFrstVmsIfscId();
        this.secdVmsIfscId = req.getSecdVmsIfscId();
        this.thirVmsIfscId = req.getThirVmsIfscId();
        this.fourVmsIfscId = req.getFourVmsIfscId();
        this.frstImgIfscId = req.getFrstImgIfscId();
        this.secdImgIfscId = req.getSecdImgIfscId();
        this.thirImgIfscId = req.getThirImgIfscId();
        this.fourImgIfscId = req.getFourImgIfscId();
        this.symbLibNmbr = req.getSymbLibNmbr();
        this.strmAddr = req.getStrmAddr();
        this.useYn = req.getUseYn();
        this.schWeek1 = req.getSchWeek1();
        this.schWeek2 = req.getSchWeek2();
        this.schWeek3 = req.getSchWeek3();
        this.schWeek4 = req.getSchWeek4();
        this.schWeek5 = req.getSchWeek5();
        this.schWeek6 = req.getSchWeek6();
        this.schWeek7 = req.getSchWeek7();
        this.dsplCngsYn = req.getDsplCngsYn();
    }

}
