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

import com.oqpo.api.entity.pomng.PchOdrDtlPtclEntity;
import com.oqpo.api.entity.stockmng.WhsProcInfoPtclEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class SaveWarehouseProcRequest {
    @NotBlank
    @ApiModelProperty(value = "CRUD")
    private String viewCd;

    @NotBlank
    @ApiModelProperty(value = "브랜드아이디") private String brandId;

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

    @ApiModelProperty(value = "매장아이디-매장납품일경우 필수") private String storeId;

    @ApiModelProperty(value = "납품서파일번호") private String  dlvCnfmDocFileNo ;

    @ApiModelProperty(value = "입고 리스트")
    private List<WareHouseProcDataList> gridInsertData;


    public List<WhsProcInfoPtclEntity> toCodeEntities(List<WareHouseProcDataList> gridData) {
        List<WhsProcInfoPtclEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;

        gridData.forEach(x -> {
            WhsProcInfoPtclEntity entity = new WhsProcInfoPtclEntity();
            entity.setDlvSttmtUnqNo(x.getDlvSttmtUnqNo());
            entity.setDlvSttmtDtlNo(x.getDlvSttmtDtlNo());
            entity.setItemId(x.getItemId());
            entity.setWhsQty(x.getWhsQty());
            entities.add(entity);
        });
        return entities;
    }

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

        @NotBlank
        @ApiModelProperty(value = "납품서번호") private String dlvSttmtUnqNo;

        @NotBlank
        @ApiModelProperty(value = "납품서항번") private String dlvSttmtDtlNo;

        @ApiModelProperty(value = "품목아이디") private String itemId;

        @NotBlank
        @ApiModelProperty(value = "입고수량") private Integer whsQty;


    }
}
