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

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.AuthEntity;
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 AuthSearchListResponse {
    @ApiModelProperty(value = "조회리스트")
    private List<SearchAuth> searchList;

    public static AuthSearchListResponse toDTO(List<AuthEntity> entities) {
        if (entities == null) return null;
        return AuthSearchListResponse.builder()
                .searchList(entities.stream()
                        .map(m -> SearchAuth.builder()
                                .authNo(m.getAuthNo())
                                .authNm(m.getAuthNm())
                                .authTpNm(m.getAuthTpNm())
                                .topMenuNo(m.getTopMenuNo())
                                .useYn(m.getUseYn())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

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

        @ApiModelProperty(value = "권한번호")
        private String authNo;

        @ApiModelProperty(value = "권한명")
        private String authNm;

        @ApiModelProperty(value = "권한타입명")
        private String authTpNm;

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

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