package com.its.op.entity.its.code;

import com.its.op.dto.its.code.TbSectGradClsfDto;
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_SECT_GRAD")
public class TbSectGrad implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("구간 등급 코드")  // N VARCHAR(7)
    @Id
    @Column(name = "SECT_GRAD_CD", nullable = false, length = 7)
    private String sectGradCd;

    @ApiModelProperty("구간 등급 명")  // Y VARCHAR(40)
    @Column(name = "SECT_GRAD_NM", length = 40)
    private String sectGradNm;

    public TbSectGradClsfDto toDto() {
        return TbSectGradClsfDto.builder()
                .sectGradCd(this.sectGradCd)
                .sectGradNm(this.sectGradNm)
                .sectGradDesc("[" + this.sectGradCd + "] " + this.sectGradNm)
                .build();
    }

    public TbSectGrad(String sectGradCd) {
        this.sectGradCd = sectGradCd;
    }

    public void updateInfo(TbSectGradClsfDto.TbSectGradClsfUpdReq req) {
        this.sectGradNm = req.getSectGradNm();
    }

}
