package com.oqpo.api.web.dto.response.rtnmng.rtnReq;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.pomng.PchReqDtlPtclEntity;
import com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.List;
import java.util.stream.Collectors;


@Getter
@Setter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@JsonInclude(JsonInclude.Include.ALWAYS)
public class RtnReqRejectTargetResponse {

    @ApiModelProperty(value = "그리드 페이지")
    private Integer gridPage;

    @ApiModelProperty(value = "그리드 전체 페이지 수")
    private Integer gridTotal;

    @ApiModelProperty(value = "그리드 전체 목록 수")
    private Integer gridRecords;

    @ApiModelProperty(value = "그리드 리스트")
    private List<PchReqInfo> gridRows;


    public static RtnReqRejectTargetResponse toDTO(List<RtnReqBaseInfoEntity> entities) {
        if (entities == null) return null;

        return RtnReqRejectTargetResponse.builder()
                .gridPage(0)
                .gridRecords(entities.size())
                .gridTotal(0)
                .gridRows(entities.stream()
                        .map(m -> PchReqInfo.builder()
                                .rtnReqUnqNo(m.getRtnReqUnqNo() == null ? "" : m.getRtnReqUnqNo())
                                .rtnReqDtlNo(m.getRtnReqDtlInfo() == null ? "" : m.getRtnReqDtlInfo().getRtnReqDtlNo() == null ? "" : m.getRtnReqDtlInfo().getRtnReqDtlNo())
                                .itemId(m.getRtnReqDtlInfo() == null ? "" : m.getRtnReqDtlInfo().getItemId() == null ? "" : m.getRtnReqDtlInfo().getItemId())
                                .itemNm(m.getRtnReqDtlInfo() == null ? "" : m.getRtnReqDtlInfo().getItemNm() == null ? "" : m.getRtnReqDtlInfo().getItemNm())
                                .rtnQty(m.getRtnReqDtlInfo() == null ? 0 : m.getRtnReqDtlInfo().getRtnQty() == null ? 0 : m.getRtnReqDtlInfo().getRtnQty())
                                .rtnAmt(m.getRtnReqDtlInfo() == null ? 0 : m.getRtnReqDtlInfo().getRtnAmt() == null ? 0 : m.getRtnReqDtlInfo().getRtnAmt())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }


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

        @ApiModelProperty(value = "반품요청번호")
        private String rtnReqUnqNo;

        @ApiModelProperty(value = "반품요청상세항번")
        private String rtnReqDtlNo;

        @ApiModelProperty(value = "품목아이디")
        private String itemId;

        @ApiModelProperty(value = "품목명")
        private String itemNm;

        @ApiModelProperty(value = "반품요청수량")
        private Integer rtnQty;

        @ApiModelProperty(value = "반품요청금액")
        private Long rtnAmt;

    }






}
