package com.its.op.entity.its.oper;

import com.its.op.dto.its.oper.TbOperSystMenuDto;
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;

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

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

    @ApiModelProperty("")  // N VARCHAR2(100)
    @Id
    @Column(name = "MENU_ID", nullable = false, length = 100)
    private String menuId;

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

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

    @ApiModelProperty("상위메뉴ID")  // Y VARCHAR2(100)
    @Column(name = "PARENT_MENU_ID", length = 100)
    private String parentMenuId;

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

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

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

    public TbOperSystMenu(String operSystId, String menuId) {
        this.operSystId = operSystId;
        this.menuId = menuId;
    }

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

}
