package com.its.op.entity.its.rse;

import com.its.op.dto.its.rse.TbRseCtlrCnncHsDto;
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;

/**
 * RSE 접속로그 이력 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("RSE 접속로그 이력")
@Entity
@Table(name = "TB_RSE_CTLR_CNNC_HS")
@IdClass(TbRseCtlrCnncHsKey.class)
public class TbRseCtlrCnncHs implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("수집 일시")  // N VARCHAR2(14)
    @Id
    @Column(name = "CLCT_DT", nullable = false, length = 14)
    private String clctDt;

    @ApiModelProperty("로그 유형")  // Y VARCHAR2(7)
    @Column(name = "LOG_TYPE", length = 7)
    private String logType;

    @ApiModelProperty("로그 ID")  // Y VARCHAR2(64)
    @Column(name = "LOG_ID", length = 64)
    private String logId;

    @ApiModelProperty("로그 ADDRESS")  // Y VARCHAR2(20)
    @Column(name = "LOG_ADDRESS", length = 20)
    private String logAddress;

    public TbRseCtlrCnncHsDto toDto() {
        return TbRseCtlrCnncHsDto.builder()
                .rseCtlrNmbr(this.rseCtlrNmbr)
                .clctDt(this.clctDt)
                .logType(this.logType)
                .logId(this.logId)
                .logAddress(this.logAddress)
                .build();
    }

    public TbRseCtlrCnncHs(Long rseCtlrNmbr, String clctDt) {
        this.rseCtlrNmbr = rseCtlrNmbr;
        this.clctDt = clctDt;
    }

    public void updateInfo(TbRseCtlrCnncHsDto.TbRseCtlrCnncHsUpdReq req) {
        this.logType = req.getLogType();
        this.logId = req.getLogId();
        this.logAddress = req.getLogAddress();
    }

}
