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

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

    public static NumbSearchListResponse toDTO(List<NumbEntity> entities) {
        if (entities == null) return null;
        return NumbSearchListResponse.builder()
                .searchList(entities.stream()
                        .map(m -> SearchNumb.builder()
                                .numNo(m.getNumNo())
                                .defiInfo(m.getDefiInfo())
                                .numNm(m.getNumNm())
                                .useYn(m.getUseYn())
                                .useYnNm(m.getUseYnNm())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SearchNumb {
        @ApiModelProperty(value = "채번번호")
        private Integer numNo;

        @ApiModelProperty(value = "정의어")
        private String defiInfo;

        @ApiModelProperty(value = "채번명")
        private String numNm;

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

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