package com.oqpo.api.web.dto.request.pomng.pchOrd;

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

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

@Getter
@Setter
public class CancelPchOrdDtlRequest {

    @NotBlank
    @ApiModelProperty(value = "CRUD")
    private String viewCd;

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

    @NotBlank
    @ApiModelProperty(value = "발주번호")
    private String pchPodrUnqNo;

    @NotBlank
    @ApiModelProperty(value = "배송방법")
    private String dlvDvsn;

    @ApiModelProperty(value = "출고창고")
    private String shmtWhsId;

    @ApiModelProperty(value = "출고Location")
    private String shmtLocation;

    @ApiModelProperty(value = "매장아이디")
    private String storeId;

    @ApiModelProperty(value = "삭제대상 발주 품목 리스트")
    private List<CancelPoItemList> gridUpdateData;


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

        gridData.forEach(x -> {
            PchOdrDtlPtclEntity entity = new PchOdrDtlPtclEntity();
            entity.setPchPodrUnqNo(x.getPchPodrUnqNo());
            entity.setPchPodrDtlNo(x.getPchPodrDtlNo());
            entity.setPodrAmt(x.getPodrAmt());
            entity.setItemId(x.getItemId());
            entity.setPodrQty(x.getPodrQty());
            entities.add(entity);
        });
        return entities;
    }

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

        @ApiModelProperty(value = "구매요청고유번호") private String pchPodrUnqNo;
        @ApiModelProperty(value = "구매요청상세번호") private String pchPodrDtlNo;
        @ApiModelProperty(value = "품목아이디") private String itemId;
        @ApiModelProperty(value = "발주수량") private Integer podrQty;
        @ApiModelProperty(value = "발주 금액") private Long podrAmt;
    }
}
