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

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

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

@Getter
@Setter
public class SaveStockCddRequest {

    @ApiModelProperty(value = "실사구분")
    private String cddDvsn;
    @ApiModelProperty(value = "실사일자")
    private String cddDt;
    @ApiModelProperty(value = "실사시각")
    private String cddTm;
    @ApiModelProperty(value = "브랜드아이디")
    private String brandId;
    @ApiModelProperty(value = "매장아이디(매장재고관리)")
    private String storeId;
    @ApiModelProperty(value = "창고아이디")
    private String whsId;
    @ApiModelProperty(value = "LOCATION")
    private String location;

    @ApiModelProperty(value = "재고실사 품목리스트")
    private List<SaveStockCddRequest.StockCddReqData> gridInsertData;

    public List<StckCddMgntDtlEntity> toEntities(List<SaveStockCddRequest.StockCddReqData> gridData) {
        List<StckCddMgntDtlEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;

        gridData.forEach(x -> {
            StckCddMgntDtlEntity entity = new StckCddMgntDtlEntity();
            entity.setItemId(x.getItemId());
            entity.setCddQty(x.getCddQty());
            entities.add(entity);
        });
        return entities;
    }

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

        @ApiModelProperty(value = "품목아이디")
        private String itemId;
        @ApiModelProperty(value = "실사수량")
        private int cddQty;

    }
}
