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

import com.oqpo.api.entity.stockmng.WhsMgntBaseLocEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class SaveWhsInfoRequest {

    @ApiModelProperty(value = "브랜드아이디")
    private String brandId;
    @ApiModelProperty(value = "창고아이디")
    private String whsId;
    @ApiModelProperty(value = "창고명")
    private String whsNm;
    @ApiModelProperty(value = "창고관리구분(본사,매장)")
    private String whsDvsn;
    @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 storeId;

    @ApiModelProperty(value = "위치정보 리스트")
    private List<SaveWhsInfoRequest.LocationReqData> gridInsertData;
    @ApiModelProperty(value = "위치정보 리스트")
    private List<SaveWhsInfoRequest.LocationReqData> gridUpdateData;
    @ApiModelProperty(value = "위치정보 리스트")
    private List<SaveWhsInfoRequest.LocationReqData> gridDeleteData;

    public List<WhsMgntBaseLocEntity> toEntities(List<SaveWhsInfoRequest.LocationReqData> gridData) {
        List<WhsMgntBaseLocEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;

        gridData.forEach(x -> {
            WhsMgntBaseLocEntity entity = new WhsMgntBaseLocEntity();
            entity.setBrandId(brandId);
            entity.setWhsId(whsId);
            entity.setLocation(x.getLocation());
            entity.setLocationNm(x.getLocationNm());
            entity.setStckDvsn(x.getStckDvsn());
            entity.setLocStCd(x.getLocStCd());
            entities.add(entity);
        });
        return entities;
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class LocationReqData {

        @ApiModelProperty(value = "LOCATION")
        private String location;
        @ApiModelProperty(value = "로케이션명")
        private String locationNm;
        @ApiModelProperty(value = "재고상태구분")
        private String stckDvsn;
        @ApiModelProperty(value = "창고상태코드")
        private String locStCd;

    }
}
