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

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.stockmng.WhsMgntBaseInfoEntity;
import com.oqpo.api.entity.stockmng.WhsMgntBaseLocEntity;
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 WhsMngInfoResponse {

    @ApiModelProperty(value = "브랜드아이디")
    private String brandId;
    @ApiModelProperty(value = "브랜드명")
    private String brandNm;
    @ApiModelProperty(value = "창고아이디")
    private String whsId;
    @ApiModelProperty(value = "창고명")
    private String whsNm;
    @ApiModelProperty(value = "창고관리구분(본사,매장)")
    private String whsDvsn;
    @ApiModelProperty(value = "창고관리명")
    private String whsDvsnNm;
    @ApiModelProperty(value = "담당자명")
    private String mgrNm;
    @ApiModelProperty(value = "담당자전화번호")
    private String mgrTelNo;
    @ApiModelProperty(value = "우편번호")
    private String zipNo;
    @ApiModelProperty(value = "주소1")
    private String addr1;
    @ApiModelProperty(value = "주소2")
    private String addr2;
    @ApiModelProperty(value = "창고상태코드")
    private String whsStCd;
    @ApiModelProperty(value = "창고상태명")
    private String whsStNm;
    @ApiModelProperty(value = "매장아이디")
    private String storeId;
    @ApiModelProperty(value = "매장명")
    private String storeNm;
    @ApiModelProperty(value = "시스템등록일시")
    private String sysRegDttm;
    @ApiModelProperty(value = "시스템등록아이디")
    private String sysRegId;
    @ApiModelProperty(value = "시스템변경일시")
    private String sysChgDttm;
    @ApiModelProperty(value = "시스템변경아이디")
    private String sysChgId;

    @ApiModelProperty(value = "위치정보 리스트")
    private List<LocationInfo> locationInfoList;

    public static WhsMngInfoResponse toDTO(WhsMgntBaseInfoEntity entity, List<WhsMgntBaseLocEntity> locationInfoList) {
        if (entity == null) return null;
        return WhsMngInfoResponse.builder()
                .brandId(entity.getBrandId())
                .brandNm(entity.getBrandNm())
                .whsId(entity.getWhsId())
                .whsNm(entity.getWhsNm())
                .whsDvsn(entity.getWhsDvsn())
                .whsDvsnNm(entity.getWhsDvsnNm())
                .mgrNm(entity.getMgrNm())
                .mgrTelNo(entity.getMgrTelNo())
                .zipNo(entity.getZipNo())
                .addr1(entity.getAddr1())
                .addr2(entity.getAddr2())
                .whsStCd(entity.getWhsStCd())
                .whsStNm(entity.getWhsStNm())
                .storeId(entity.getStoreId())
                .storeNm(entity.getStoreNm())
                .sysRegDttm(entity.getSysRegDttm())
                .sysRegId(entity.getSysRegId())
                .sysChgDttm(entity.getSysChgDttm())
                .sysChgId(entity.getSysChgId())
                .locationInfoList(locationInfoList.stream()
                        .map(m -> LocationInfo.builder()
                                .location(m.getLocation())
                                .locationNm(m.getLocationNm())
                                .stckDvsn(m.getStckDvsn())
                                .stckDvsnNm(m.getStckDvsnNm())
                                .locStCd(m.getLocStCd())
                                .locStNm(m.getLocStNm())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class LocationInfo {
        @ApiModelProperty(value = "LOCATION")
        private String location;
        @ApiModelProperty(value = "로케이션명")
        private String locationNm;
        @ApiModelProperty(value = "재고상태구분")
        private String stckDvsn;
        @ApiModelProperty(value = "재고상태구분명")
        private String stckDvsnNm;
        @ApiModelProperty(value = "창고상태코드")
        private String locStCd;
        @ApiModelProperty(value = "창고상태명")
        private String locStNm;
    }

}
