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

import com.oqpo.api.entity.rtnmng.RtnOdrDtlPtclEntity;
import com.oqpo.api.entity.rtnmng.RtnReqDtlPtclEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

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

    @NotBlank
    @ApiModelProperty(value = "JOB  반품요청건 발주 - R  , 신규발주 - P")
    private String jobCd;

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

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

    @NotBlank
    @ApiModelProperty(value = "수거구분") private String colDvsn;

    @NotBlank
    @ApiModelProperty(value = "수거요청일") private String colReqDt;

    @NotBlank
    @ApiModelProperty(value = "반품요청구분  요청반품 RR01  미요청 RR02") private String rtnReqDvsn;  // 신규 RR01,

    @ApiModelProperty(value = "공급사아이디") private String spplyId;
    @ApiModelProperty(value = "입고창고아이디") private String whsId;
    @ApiModelProperty(value = "입고LOCATION") private String location;
    @ApiModelProperty(value = "수거창고아이디") private String rtnWhsId;
    @ApiModelProperty(value = "수거LOCATION") private String rtnLocation;
    @ApiModelProperty(value = "매장아이디") private String storeId;


    @ApiModelProperty(value = "등록 품목리스트")
    private List<SaveRtnOdrItemList> gridInsertData;


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

        gridData.forEach(x -> {
            RtnOdrDtlPtclEntity entity = new RtnOdrDtlPtclEntity();
            entity.setRtnReqUnqNo(x.getRtnReqUnqNo());
            entity.setRtnReqDtlNo(x.getRtnReqDtlNo());
            entity.setItemId(x.getItemId());
            entity.setRtnQty(x.getRtnQty());
            entity.setRtnReqQty(x.getRtnReqQty());
            entity.setBrandUnitUnqNo(x.getBrandUnitUnqNo());
            entity.setStoreUnitUnqNo(x.getStoreUnitUnqNo());
            entity.setRtnDvsn(x.getRtnDvsn());
            entity.setRtnRsnDvsn(x.getRtnRsnDvsn());
            entity.setRtnRsn(x.getRtnRsn());
            entities.add(entity);
        });
        return entities;
    }

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

        @ApiModelProperty(value = "반품요청고유번호") private String rtnReqUnqNo;
        @ApiModelProperty(value = "반품요청상세번호") private String rtnReqDtlNo;
        @ApiModelProperty(value = "품목아이디") private String itemId;
        @ApiModelProperty(value = "반품요청수량") private Integer rtnReqQty;
        @ApiModelProperty(value = "반품발주수량") private Integer rtnQty;
        @ApiModelProperty(value = "브랜드단가고유번호") private String brandUnitUnqNo;
        @ApiModelProperty(value = "매장단가고유번호") private String storeUnitUnqNo;
        @ApiModelProperty(value = "반품구분") private String rtnDvsn;
        @ApiModelProperty(value = "반품사유구분") private String rtnRsnDvsn;
        @ApiModelProperty(value = "반품사유") private String rtnRsn;
    }
}
