package com.its.op.entity.its.cctv;

import com.its.op.dto.its.cctv.TbCctvPsetDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 * CCTV 프리셋 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("CCTV 프리셋")
@Entity
@Table(name = "TB_CCTV_PSET")
@IdClass(TbCctvPsetKey.class)
public class TbCctvPset implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("CCTV 관리 번호")  // N NUMBER(10)
    @Id
    @Column(name = "CCTV_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long cctvCtlrNmbr;

    @ApiModelProperty("프리셋 번호")  // N VARCHAR2(3)
    @Id
    @Column(name = "PSET_NMBR", nullable = false, length = 3)
    private String psetNmbr;

    @ApiModelProperty("팬 값")  // Y NUMBER(5)
    @Column(name = "PAN_VAL", columnDefinition = "NUMBER", length = 5)
    private Integer panVal;

    @ApiModelProperty("틸트 값")  // Y NUMBER(5)
    @Column(name = "TILT_VAL", columnDefinition = "NUMBER", length = 5)
    private Integer tiltVal;

    @ApiModelProperty("줌 값")  // Y NUMBER(5)
    @Column(name = "ZOOM_VAL", columnDefinition = "NUMBER", length = 5)
    private Integer zoomVal;

    @ApiModelProperty("초점 값")  // Y NUMBER(5)
    @Column(name = "FOCS_VAL", columnDefinition = "NUMBER", length = 5)
    private Integer focsVal;

    @ApiModelProperty("프리셋 명")  // Y VARCHAR2(100)
    @Column(name = "PSET_NM", length = 100)
    private String psetNm;

    @ApiModelProperty("디폴트 여부")  // Y CHAR(1)
    @Column(name = "DFLT_YN", columnDefinition = "CHAR", length = 1)
    private String dfltYn;

    public TbCctvPsetDto toDto() {
        return TbCctvPsetDto.builder()
                .cctvCtlrNmbr(this.cctvCtlrNmbr)
                .psetNmbr(this.psetNmbr)
                .panVal(this.panVal)
                .tiltVal(this.tiltVal)
                .zoomVal(this.zoomVal)
                .focsVal(this.focsVal)
                .psetNm(this.psetNm)
                .dfltYn(this.dfltYn)
                .build();
    }

    public TbCctvPset(Long cctvCtlrNmbr, String psetNmbr) {
        this.cctvCtlrNmbr = cctvCtlrNmbr;
        this.psetNmbr = psetNmbr;
    }

    public void updateInfo(TbCctvPsetDto.TbCctvPsetUpdReq req) {
        this.panVal = req.getPanVal();
        this.tiltVal = req.getTiltVal();
        this.zoomVal = req.getZoomVal();
        this.focsVal = req.getFocsVal();
        this.psetNm = req.getPsetNm();
        this.dfltYn = req.getDfltYn();
    }

}
