package com.oqpo.api.web.dto.response.menu;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.MenuEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Getter
@Setter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@JsonInclude(JsonInclude.Include.ALWAYS) //null 값 전송
public class MenuAuthListResponse {

    @ApiModelProperty(value = "CRUD")
    private String viewCd;

    @ApiModelProperty(value = "메뉴번호")
    private Integer menuNo;

    @ApiModelProperty(value = "메뉴명")
    private String menuNm;

    @ApiModelProperty(value = "메뉴번호")
    private Integer topMenuNo;

    @ApiModelProperty(value = "상위메뉴명")
    private String topMenuNm;

    @ApiModelProperty(value = "읽기권한")
    private String readYn;

    @ApiModelProperty(value = "쓰기권한")
    private String writeYn;


    public static MenuAuthListResponse toDTO(MenuEntity entity) {
        if (entity == null) return null;
        return MenuAuthListResponse.builder()
                .viewCd("R")
                .menuNo(entity.getMenuNo())
                .menuNm(entity.getMenuNm())
                .topMenuNo(entity.getTopMenuNo())
                .topMenuNm(entity.getTopMenuNm())
                .readYn(entity.getAuthDtl().getReadYn())
                .writeYn(entity.getAuthDtl().getWriteYn())
                .build();
    }

}
