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

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 SaveSpplyDlvRequest {
    @NotBlank
    @ApiModelProperty(value = "CRUD")
    private String viewCd;

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

    @NotBlank
    @ApiModelProperty(value = "공급사아이디") private String spplyId;

    @NotBlank
    @ApiModelProperty(value = "납품예정일") private String dlvSchDt;

    @NotBlank
    @ApiModelProperty(value = "납품담당자명") private String dlvMgrNm;

    @NotBlank
    @ApiModelProperty(value = "납품담당자연락처") private String dlvMgrTelNo;


    @ApiModelProperty(value = "출하지시대상 리스트")
    private List<InstShmtItemDataList> gridInsertData;


    public List<PchOdrDtlPtclEntity> toCodeEntities(List<InstShmtItemDataList> 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.setShmtQty(x.getShmtQty());
            entity.setExpryDate(x.getExpryDate());
            entities.add(entity);
        });
        return entities;
    }

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

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

        @NotBlank
        @ApiModelProperty(value = "구매발주항번") private String pchPodrDtlNo;

        @NotBlank
        @ApiModelProperty(value = "출하수량") private Integer shmtQty ;

        @ApiModelProperty(value = "유통기한") private String  expryDate;

        @ApiModelProperty(value = "비고") private String deliDesc ;


    }
}
