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

import com.oqpo.api.entity.rtnmng.RtnOdrDtlPtclEntity;
import com.oqpo.api.web.dto.request.GridRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

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

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

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


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

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

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

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

    }

    protected InstInitColOdrRequest(Integer gridSize, Integer gridPage, String sidx, String sord, Boolean pagingYn, Integer gridFirst) {
        super(gridSize, gridPage, sidx, sord, pagingYn, gridFirst);
    }
}
