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

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

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

/**
 * 운영시스템메뉴 Entity Class
 */
@Getter
@NoArgsConstructor
@Builder
@AllArgsConstructor
@ApiModel("운영시스템메뉴")
@Entity
@Table(name = "TB_OPERSYST_MENU")
public class TbOperSystMenu implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("메뉴명")  // Y VARCHAR(100)
    @Column(name = "MENU_NAME", length = 100)
    private String menuName;

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

    @ApiModelProperty("메뉴레벨")  // Y NUMBER(2)
    @Column(name = "MENU_LEVL", columnDefinition = "NUMBER", length = 2)
    private Integer menuLevl;

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

    @Transient
    private String  operSystNm;
    public void setOperSystNm(String operSystNm) {
        this.operSystNm = operSystNm;
    }

    public TbOperSystMenuDto toDto() {
        return TbOperSystMenuDto.builder()
                .operSystMenuId(this.operSystMenuId)
                .menuName(this.menuName)
                .delYn(this.delYn)
                .menuLevl(this.menuLevl)
                .operSystId(this.operSystId)
                .build();
    }

    public TbOperSystMenu(String operSystMenuId) {
        this.operSystMenuId = operSystMenuId;
    }

    public void updateInfo(TbOperSystMenuDto.TbOperSystMenuUpdReq req) {
        this.menuName = req.getMenuName();
        this.delYn = req.getDelYn();
        this.menuLevl = req.getMenuLevl();
        this.operSystId = req.getOperSystId();
    }

}
