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

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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class SaveStockBaseInfoRequest {

    @ApiModelProperty(value = "브랜드아이디")
    private String brandId;
    @ApiModelProperty(value = "창고아이디")
    private String whsId;
    @ApiModelProperty(value = "LOCATION")
    private String location;

    @ApiModelProperty(value = "재고기준정보 품목리스트")
    private List<SaveStockBaseInfoRequest.StockBaseInfoReqData> gridInsertData;
    @ApiModelProperty(value = "재고기준정보 품목리스트")
    private List<SaveStockBaseInfoRequest.StockBaseInfoReqData> gridUpdateData;
    @ApiModelProperty(value = "재고기준정보 품목리스트")
    private List<SaveStockBaseInfoRequest.StockBaseInfoReqData> gridDeleteData;

    public List<StckMgntBaseInfoEntity> toEntities(List<SaveStockBaseInfoRequest.StockBaseInfoReqData> gridData) {
        List<StckMgntBaseInfoEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;

        gridData.forEach(x -> {
            StckMgntBaseInfoEntity entity = new StckMgntBaseInfoEntity();
            entity.setBrandId(brandId);
            entity.setWhsId(whsId);
            entity.setLocation(location);
            entity.setItemId(x.getItemId());
            entity.setPrpStckQty(x.getPrpStckQty());
            entity.setSftStckRt(x.getSftStckRt());
            entities.add(entity);
        });
        return entities;
    }

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

        @ApiModelProperty(value = "품목아이디")
        private String itemId;
        @ApiModelProperty(value = "적정재고수량")
        private int prpStckQty;
        @ApiModelProperty(value = "안전재고비율")
        private BigDecimal sftStckRt;

    }
}
