package com.its.op.entity.its.wcam;

import com.its.op.dto.its.wcam.TbWcamCtlrSttsHsDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

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

/**
 * 웹 카메라 상태 이력 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("웹 카메라 상태 이력")
@Entity
@IdClass(TbWcamCtrlSttsHsKey.class)
@Table(name = "TB_WCAM_CTLR_STTS_HS")
public class TbWcamCtlrSttsHs implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("생성 일시")  // N VARCHAR2(14)
    @Id
    @Column(name = "CRTN_DT", nullable = false, length = 14)
    private String crtnDt;

    @ApiModelProperty("웹카메라 제어기번호")  // N NUMBER(10)
    @Id
    @Column(name = "WCAM_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long wcamCtlrNmbr;

    @ApiModelProperty("통신 상태 코드('CMS')")  // Y VARCHAR2(7)
    @Column(name = "CMNC_STTS_CD", length = 7)
    private String cmncSttsCd;

    @OneToOne
    @JoinColumn(insertable=false, updatable=false, name="WCAM_CTLR_NMBR", referencedColumnName = "WCAM_CTLR_NMBR")
    @NotFound(action = NotFoundAction.IGNORE)
    private TbWcamCtlr wcam;

    public TbWcamCtlrSttsHsDto toDto() {
        return TbWcamCtlrSttsHsDto.builder()
                .crtnDt(this.crtnDt)
                .wcamCtlrNmbr(this.wcamCtlrNmbr)
                .cmncSttsCd(this.cmncSttsCd)
                .build();
    }

    public void updateInfo(TbWcamCtlrSttsHsDto.TbWcamCtlrSttsHsUpdReq req) {
        this.crtnDt = req.getCrtnDt();
        this.wcamCtlrNmbr = req.getWcamCtlrNmbr();
        this.cmncSttsCd = req.getCmncSttsCd();
    }

}
