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

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

    public static WhsLocationPopListResponse toDTO(List<WhsMgntBaseInfoEntity> entities) {
        if (entities == null) return null;
        return WhsLocationPopListResponse.builder()
                .searchList(entities.stream()
                        .map(m -> SearchCode.builder()
                                .brandId(m.getBrandId())
                                .brandNm(m.getBrandNm())
                                .whsId(m.getWhsId())
                                .whsNm(m.getWhsNm())
                                .location(m.getLocationInfo() == null ? "" : m.getLocationInfo().getLocation() == null ? "" : m.getLocationInfo().getLocation() )
                                .locationNm(m.getLocationInfo() == null ? "" : m.getLocationInfo().getLocationNm() == null ? "" : m.getLocationInfo().getLocationNm() )
                                .stckDvsn(m.getLocationInfo() == null ? "" : m.getLocationInfo().getStckDvsn() == null ? "" : m.getLocationInfo().getStckDvsn() )
                                .stckDvsnNm(m.getLocationInfo() == null ? "" : m.getLocationInfo().getStckDvsnNm() == null ? "" : m.getLocationInfo().getStckDvsnNm() )
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SearchCode {
        @ApiModelProperty(value = "브랜드아이디")
        private String brandId;

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

        @ApiModelProperty(value = "창고아이디")
        private String whsId;

        @ApiModelProperty(value = "창고명")
        private String whsNm;

        @ApiModelProperty(value = "로케이션번호")
        private String location;

        @ApiModelProperty(value = "로케이션명")
        private String locationNm;

        @ApiModelProperty(value = "창고구분코드")
        private String stckDvsn;

        @ApiModelProperty(value = "창고구분명")
        private String stckDvsnNm;
    }
}
