package com.oqpo.api.web.dto.response.stinfo.item;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.CodeEntity;
import com.oqpo.api.entity.stinfo.ItemClassMngEntity;
import com.oqpo.api.web.dto.response.code.CodeSearchListResponse;
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 ItemClassLevelResponse {
    @ApiModelProperty(value = "분류리스트")
    private List<ItemClassLevelResponse.SearchItemClass> searchList;

    public static ItemClassLevelResponse toDTO(List<ItemClassMngEntity> entities) {
        if (entities == null) return null;
        return ItemClassLevelResponse.builder()
                .searchList(entities.stream()
                        .map(m -> SearchItemClass.builder()
                                .itemClass(m.getItemClass())
                                .itemClassNm(m.getItemClassNm())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SearchItemClass {
        @ApiModelProperty(value = "분류코드")
        private String itemClass;

        @ApiModelProperty(value = "분류명")
        private String itemClassNm;

    }
}
