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

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

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

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

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

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


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


    public List<RtnOdrDtlPtclEntity> toCodeEntities(List<InstColItemDataList> 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());
            entities.add(entity);
        });
        return entities;
    }

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

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

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

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


    }
}
