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

import com.its.op.dto.its.rse.TbRseObuClctHsDto;
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 OBU 수집 이력 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("RSE OBU 수집 이력")
@Entity
@Table(name = "TB_RSE_OBU_CLCT_HS")
@IdClass(TbRseObuClctHsKey.class)
public class TbRseObuClctHs 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("OBU 인식 번호")  // N VARCHAR2(200)
    @Id
    @Column(name = "OBU_IDNT_NMBR", nullable = false, length = 200)
    private String obuIdntNmbr;

    @ApiModelProperty("차종")  // Y VARCHAR2(7)
    @Column(name = "CTYP", length = 7)
    private String ctyp;

    @ApiModelProperty("OBU 종류")  // Y VARCHAR2(7)
    @Column(name = "OBU_KIND", length = 7)
    private String obuKind;

    public TbRseObuClctHsDto toDto() {
        return TbRseObuClctHsDto.builder()
                .rseCtlrNmbr(this.rseCtlrNmbr)
                .clctDt(this.clctDt)
                .obuIdntNmbr(this.obuIdntNmbr)
                .ctyp(this.ctyp)
                .obuKind(this.obuKind)
                .build();
    }

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

    public void updateInfo(TbRseObuClctHsDto.TbRseObuClctHsUpdReq req) {
        this.ctyp = req.getCtyp();
        this.obuKind = req.getObuKind();
    }

}
