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

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.MemberEntity;
import com.oqpo.api.entity.oper.MenuEntity;
import com.oqpo.api.entity.oper.UserMngEntity;
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)
public class MsessionResponse {
    @ApiModelProperty(value = "사용자ID")
    private String userId;
	
    @ApiModelProperty(value = "사용자명")
    private String userNm;

    @ApiModelProperty(value = "이메일")
    private String email;

    @ApiModelProperty(value = "전화번호")
    private String telNo;

    @ApiModelProperty(value = "매장 리스트")
    private List<ShopInfo> storeList;

    @ApiModelProperty(value = "메뉴 리스트")
    private List<MenuInfo> menuList;

    public static MsessionResponse toDTO(MemberEntity entity, UserMngEntity userEntity, List<MenuEntity> menuList /*, List<NkUserStoreEntity> shopList*/) {
        if (entity == null) return null;
        return MsessionResponse.builder()
                .userId(entity.getUserId())
                .userNm(userEntity.getUserNm())
                .email(userEntity.getEmail())
                .telNo(userEntity.getTelNo())
                .menuList(menuList.stream()
                        .map(m -> MenuInfo.builder()
                                .menuNo(m.getMenuNo())
                                .topMenuNo(m.getTopMenuNo())
                                .menuId(m.getMenuId())
                                .menuNm(m.getMenuNm())
                                .viewNum(m.getViewNum())
                                .level(m.getLevel())
                                .openCd(m.getOpenCd())
                                .build())
                        .collect(Collectors.toList()))
                /*
                .storeList(shopList.stream()
                        .map(m -> ShopInfo.builder()
                                .brandCd(m.getBrandCd())
                                .brandNm(m.getBrandNm())
                                .storeNo(m.getStoreNo())
                                .storeNm(m.getStoreNm())
                                .build())
                        .collect(Collectors.toList()))
                        */
                .build();
    }



    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class MenuInfo {

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

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

        @ApiModelProperty(value = "메뉴ID")
        private String menuId;

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

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

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

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


    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class ShopInfo {
        @ApiModelProperty(value = "브랜드코드")
        private String brandCd ;

        @ApiModelProperty(value = "브랜드명")
        private String brandNm;

        @ApiModelProperty(value = "매장번호")
        private String storeNo;

        @ApiModelProperty(value = "매장명")
        private String storeNm;
    }

}
