package com.its.api.its.model.entity.oper;

import com.its.api.its.model.dto.oper.TbOperSystDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * 운영시스템 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("운영시스템")
@Entity
@Table(name = "TB_OPERSYST")
public class TbOperSyst implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("운영시스템ID")  // N VARCHAR(30)
    @Id
    @Column(name = "OPER_SYST_ID", nullable = false, length = 30)
    private String operSystId;

    @ApiModelProperty("운영시스템명칭")  // Y VARCHAR(20)
    @Column(name = "OPER_SYST_NAME", length = 20)
    private String operSystName;

    @ApiModelProperty("생성 일시")  // Y VARCHAR(14)
    @Column(name = "CRTN_DT", length = 14)
    private String crtnDt;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
    private String delYn;

    public TbOperSystDto toDto() {
        TbOperSystDto dto = TbOperSystDto.builder()
                .operSystId(this.operSystId)
                .operSystName(this.operSystName)
                .crtnDt(this.crtnDt)
                .delYn(this.delYn)
                .build();

        dto.setOperSystDesc("[" + this.operSystId + "] " + this.operSystName);

        return dto;
    }

    public TbOperSyst(String operSystId) {
        this.operSystId = operSystId;
    }

    public void updateInfo(TbOperSystDto.TbOperSystUpdReq req) {
        this.operSystName = req.getOperSystName();
        this.crtnDt = req.getCrtnDt();
        this.delYn = req.getDelYn();
    }

}
