package com.its.api.its.model.entity.vms;

import com.its.api.its.model.dto.vms.VwVmsDsplPrstDto;
import com.its.api.utils.ItsUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 *  Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("")
@Entity
@Table(name = "VW_VMS_DSPL_PRST")
@IdClass(VwVmsDsplPrstKey.class)
public class VwVmsDsplPrst implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @ApiModelProperty("")  // N NUMBER(10)
    @Column(name = "VMS_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long vmsCtlrNmbr;

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

    @ApiModelProperty("")  // Y VARCHAR(30)
    @Column(name = "VMS_CTLR_ID", length = 30)
    private String vmsCtlrId;

    @ApiModelProperty("")  // Y VARCHAR(40)
    @Column(name = "VMS_NM", length = 40)
    private String vmsNm;

    @ApiModelProperty("")  // Y VARCHAR(200)
    @Column(name = "STRM_SESN_NM", length = 200)
    private String strmSesnNm;

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

    @ApiModelProperty("")  // Y CHAR(1)
    @Column(name = "DNLD_YN", columnDefinition = "CHAR", length = 1)
    private String dnldYn;

    @ApiModelProperty("")  // Y NUMBER(3)
    @Column(name = "VMS_MSG_DSPL_MTHD_CD", columnDefinition = "NUMBER", length = 3)
    private Integer vmsMsgDsplMthdCd;

    @ApiModelProperty("")  // Y VARCHAR(7)
    @Column(name = "TRFC_SITU_TYPE_CD", length = 7)
    private String trfcSituTypeCd;

    @ApiModelProperty("")  // Y VARCHAR(14)
    @Column(name = "DSPL_DT", length = 14)
    private String dsplDt;

    @ApiModelProperty("")  // Y VARCHAR(14)
    @Column(name = "SVC_DT", length = 14)
    private String svcDt;

    @ApiModelProperty("")  // Y BLOB
    @Lob
    @Column(name = "VMS_DSPL_MSG_IMAG")
    private byte[] vmsDsplMsgImag;

    public VwVmsDsplPrstDto toDto() {
        VwVmsDsplPrstDto dto = VwVmsDsplPrstDto.builder()
                .vmsCtlrNmbr(this.vmsCtlrNmbr)
                .vmsCtlrId(this.vmsCtlrId)
                .vmsNm(this.vmsNm)
                .strmSesnNm(this.strmSesnNm)
                .phase(this.phase)
                .dsplHh(this.dsplHh)
                .dnldYn(this.dnldYn)
                .vmsMsgDsplMthdCd(this.vmsMsgDsplMthdCd)
                .trfcSituTypeCd(this.trfcSituTypeCd)
                .dsplDt(this.dsplDt)
                .svcDt(this.svcDt)
                .vmsDsplMsgImag(this.vmsDsplMsgImag)
                .build();

        dto.setVmsDsplMsgImag(ItsUtils.convertBmpToPng(dto.getVmsDsplMsgImag()));
        dto.setImagFmt("png");
        dto.setSvcYn(ItsUtils.getServiceYn(dto.getDsplDt()));

        return dto;
    }

}
