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

import com.oqpo.api.entity.inoutmng.PickDtlPtclEntity;
import com.oqpo.api.entity.pomng.PchOdrDtlPtclEntity;
import com.oqpo.api.entity.rtnmng.RtnOdrDtlPtclEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

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

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

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

    @NotBlank
    @ApiModelProperty(value = "수거예정일") private String colSchDt;

    @NotBlank
    @ApiModelProperty(value = "수거담당자명") private String pickMgrNm;

    @NotBlank
    @ApiModelProperty(value = "수거담당자연락처") private String pickMgrTelNo;


    @ApiModelProperty(value = "수거지시대상 리스트")
    private List<InstPickItemDataList> gridInsertData;


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

        gridData.forEach(x -> {
            RtnOdrDtlPtclEntity entity = new RtnOdrDtlPtclEntity();
            entity.setRtnPodrUnqNo(x.getRtnPodrUnqNo());
            entity.setRtnPodrDtlNo(x.getRtnPodrDtlNo());
            entity.setColQty(x.getColQty());
            entity.setRtnRsnDvsn(x.getRtnRsnDvsn());
            entity.setRtnRsn(x.getRtnRsn());
            entities.add(entity);
        });
        return entities;
    }

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

        @NotBlank
        @ApiModelProperty(value = "반품발주번호") private String rtnPodrUnqNo;

        @NotBlank
        @ApiModelProperty(value = "반품발주항번") private String rtnPodrDtlNo;

        @NotBlank
        @ApiModelProperty(value = "수거수량") private Integer colQty;

        @ApiModelProperty(value = "반품사유") private String rtnRsnDvsn;
        @ApiModelProperty(value = "비고") private String rtnRsn;


    }
}
