package com.its.op.entity.its.scrs;

import com.its.op.dto.its.scrs.TbScIxrCmraMngmDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

/**
 * 카메라 관리 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("카메라 관리")
@Entity
@Table(name = "TB_SC_IXR_CMRA_MNGM")
@IdClass(TbScIxrCmraMngmKey.class)
public class TbScIxrCmraMngm implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("교차로 ID")  // N VARCHAR2(10)
    @Id
    @Column(name = "IXR_ID", nullable = false, length = 10)
    private String ixrId;

    @ApiModelProperty("카메라 ID")  // N VARCHAR2(10)
    @Id
    @Column(name = "CMRA_ID", nullable = false, length = 10)
    private String cmraId;

    @ApiModelProperty("방향 구분 코드")  // N NUMBER(1)
    @Id
    @Column(name = "DRCT_DVSN_CD", nullable = false, columnDefinition = "NUMBER", length = 1)
    private Integer drctDvsnCd;

    @ApiModelProperty("설치 위치")  // Y VARCHAR2(40)
    @Column(name = "ISTL_LCTN", length = 40)
    private String istlLctn;

    @ApiModelProperty("카메라 IP")  // Y VARCHAR2(16)
    @Column(name = "CMRA_IP", length = 16)
    private String cmraIp;

    @ApiModelProperty("카메라 PORT")  // Y VARCHAR2(4)
    @Column(name = "CMRA_PORT", length = 4)
    private String cmraPort;

    @ApiModelProperty("사용 유무")  // Y NUMBER(1)
    @Column(name = "USE_EN", columnDefinition = "NUMBER", length = 1)
    private Integer useEn;

    @ApiModelProperty("카메라 로그인 ID")  // Y VARCHAR2(16)
    @Column(name = "CMRA_LOGN_ID", length = 16)
    private String cmraLognId;

    @ApiModelProperty("카메라 로그인 비밀번호")  // Y VARCHAR2(16)
    @Column(name = "CMRA_LOGN_PW", length = 16)
    private String cmraLognPw;

    @ApiModelProperty("카메라 HTTP PORT")  // Y NUMBER(2)
    @Column(name = "CMRA_HTTP_PORT", columnDefinition = "NUMBER", length = 2)
    private Integer cmraHttpPort;

    @ApiModelProperty("스트림 URL")  // Y VARCHAR2(32)
    @Column(name = "STRE_URL", length = 32)
    private String streUrl;

    @ApiModelProperty("카메라 URL")  // Y VARCHAR2(100)
    @Column(name = "CMRA_URL", length = 100)
    private String cmraUrl;

    @ApiModelProperty("카메라 유형")  // Y NUMBER(1)
    @Column(name = "CMRA_TYPE", columnDefinition = "NUMBER", length = 1)
    private Integer cmraType;

    @ApiModelProperty("카메라 X 좌표")  // Y VARCHAR2(20)
    @Column(name = "CMRA_X_CRDN", length = 20)
    private String cmraXCrdn;

    @ApiModelProperty("카메라 Y 좌표")  // Y VARCHAR2(20)
    @Column(name = "CMRA_Y_CRDN", length = 20)
    private String cmraYCrdn;

    @ApiModelProperty("카메라 각도")  // Y NUMBER(3)
    @Column(name = "CMRA_ANGL", columnDefinition = "NUMBER", length = 3)
    private Integer cmraAngl;

    @ApiModelProperty("홈페이지 표출 유무")  // Y NUMBER(1)
    @Column(name = "HMPG_DSPL_EN", columnDefinition = "NUMBER", length = 1)
    private Integer hmpgDsplEn;

    @ApiModelProperty("버스 전용 차로 유무")  // Y NUMBER(1)
    @Column(name = "BUS_DVRS_LANE_EN", columnDefinition = "NUMBER", length = 1)
    private Integer busDvrsLaneEn;

    @ApiModelProperty("서비스 분석 유무")  // Y NUMBER(1)
    @Column(name = "SRVC_ANLY_EN", columnDefinition = "NUMBER", length = 1)
    private Integer srvcAnlyEn;

    @ApiModelProperty("차선수")  // Y NUMBER(3)
    @Column(name = "LANE_CNT", columnDefinition = "NUMBER", length = 2)
    private Integer laneCnt;

    public TbScIxrCmraMngmDto toDto() {
        return TbScIxrCmraMngmDto.builder()
                .ixrId(this.ixrId)
                .cmraId(this.cmraId)
                .drctDvsnCd(this.drctDvsnCd)
                .istlLctn(this.istlLctn)
                .cmraIp(this.cmraIp)
                .cmraPort(this.cmraPort)
                .useEn(this.useEn)
                .cmraLognId(this.cmraLognId)
                .cmraLognPw(this.cmraLognPw)
                .cmraHttpPort(this.cmraHttpPort)
                .streUrl(this.streUrl)
                .cmraUrl(this.cmraUrl)
                .cmraType(this.cmraType)
                .cmraXCrdn(this.cmraXCrdn)
                .cmraYCrdn(this.cmraYCrdn)
                .cmraAngl(this.cmraAngl)
                .hmpgDsplEn(this.hmpgDsplEn)
                .busDvrsLaneEn(this.busDvrsLaneEn)
                .srvcAnlyEn(this.srvcAnlyEn)
                .laneCnt(this.laneCnt)
                .build();
    }

    public TbScIxrCmraMngm(String ixrId, String cmraId, Integer drctDvsnCd) {
        this.ixrId = ixrId;
        this.cmraId = cmraId;
        this.drctDvsnCd = drctDvsnCd;
    }

    public void updateInfo(TbScIxrCmraMngmDto.TbScIxrCmraMngmUpdReq req) {
        this.istlLctn = req.getIstlLctn();
        this.cmraIp = req.getCmraIp();
        this.cmraPort = req.getCmraPort();
        this.useEn = req.getUseEn();
        this.cmraLognId = req.getCmraLognId();
        this.cmraLognPw = req.getCmraLognPw();
        this.cmraHttpPort = req.getCmraHttpPort();
        this.streUrl = req.getStreUrl();
        this.cmraUrl = req.getCmraUrl();
        this.cmraType = req.getCmraType();
        this.cmraXCrdn = req.getCmraXCrdn();
        this.cmraYCrdn = req.getCmraYCrdn();
        this.cmraAngl = req.getCmraAngl();
        this.hmpgDsplEn = req.getHmpgDsplEn();
        this.busDvrsLaneEn = req.getBusDvrsLaneEn();
        this.srvcAnlyEn = req.getSrvcAnlyEn();
        this.laneCnt = req.getLaneCnt();
    }

}
