package com.oqpo.api.web.dto.request.pomng.pchOrd;

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 PchReqOrdInitRequest {

    @ApiModelProperty(value = "CRUD")
    private String viewCd;

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

    @ApiModelProperty(value = "구매요청상세항번 리스트")
    private List<PchReqOrdInitRequest.PchReqOrdTarget> gridUpdateData;


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

        gridData.forEach(x -> {
            PchOdrDtlPtclEntity entity = new PchOdrDtlPtclEntity();
            entity.setPchReqUnqNo(x.getPchReqUnqNo());
            entity.setPchReqDtlNo(x.getPchReqDtlNo());
            entities.add(entity);
        });
        return entities;
    }

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

        @ApiModelProperty(value = "구매요청번호")
        private String pchReqUnqNo;

        @ApiModelProperty(value = "구매요청항번")
        private String pchReqDtlNo;

    }
}
