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.*;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@JsonInclude(JsonInclude.Include.ALWAYS) //null 값 전송
public class MenuSearchListResponse {
    @ApiModelProperty(value = "조회리스트")
    private List<SearchMenu> searchList;

    public static MenuSearchListResponse toDTO(List<MenuEntity> entities) {
        if (entities == null) return null;
        return MenuSearchListResponse.builder()
                .searchList(entities.stream()
                        .map(m -> SearchMenu.builder()
                                .menuNo(m.getMenuNo())
                                .topMenuNo(m.getTopMenuNo())
                                .menuNm(m.getMenuNm())
                                .topMenuNm(m.getTopMenuNm())
                                .viewNum(m.getViewNum())
                                .level(m.getLevel())
                                .useYn(m.getUseYn())
                                .useYnNm(m.getUseYnNm())
                                .openCd(m.getOpenCd())
                                .bMenuCnt(m.getBMenuCnt())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    @JsonInclude(JsonInclude.Include.ALWAYS) //null 값 전송
    static class SearchMenu {
        @ApiModelProperty(value = "메뉴번호")
        private int menuNo;

        @ApiModelProperty(value = "상위메뉴번호")
        private int topMenuNo;

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

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

        @ApiModelProperty(value = "출력순번")
        private int viewNum;

        @ApiModelProperty(value = "레벨")
        private int level;

        @ApiModelProperty(value = "사용여부")
        private String useYn;

        @ApiModelProperty(value = "사용여부명")
        private String useYnNm;

        @ApiModelProperty(value = "출력구분(S-시스템, T-타이틀, C-화면전환, P-팝업")
        private String openCd;

        @ApiModelProperty(value = "하위 메뉴 카운트")
        private Integer bMenuCnt;
    }
}
