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

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

    public static CodeSearchListResponse toDTO(List<CodeEntity> entities) {
        if (entities == null) return null;
        return CodeSearchListResponse.builder()
                .searchList(entities.stream()
                        .map(m -> SearchCode.builder()
                                .codeCd(m.getCodeCd())
                                .codeNm(m.getCodeNm())
                                .codeTpNm(m.getCodeTpNm())
                                .useYn(m.getUseYn())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SearchCode {
        @ApiModelProperty(value = "코드")
        private String codeCd;

        @ApiModelProperty(value = "코드명")
        private String codeNm;

        @ApiModelProperty(value = "코드타입명")
        private String codeTpNm;

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