package com.oqpo.api.web.dto.response.stockmng;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.inoutmng.DeliDtlMgntEntity;
import com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity;
import com.oqpo.api.entity.oper.FileEntity;
import com.oqpo.api.entity.stockmng.BoSaleInfoResultEntity;
import com.oqpo.api.entity.stockmng.BoSaleProcResultEntity;
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 BoSaleStoreStockResponse {

    @ApiModelProperty(value = "결과코드")
    private String code;

    @ApiModelProperty(value = "결과메세지")
    private String message;

    @ApiModelProperty(value = "브랜드코드")
    private String brandCd;

    @ApiModelProperty(value = "매장번호")
    private String storeNo;

    @ApiModelProperty(value = "판매품목리스트")
    private List<RsaleInfo> rSaleList;


    public static BoSaleStoreStockResponse toDTO(BoSaleInfoResultEntity boSaleInfo , List<BoSaleProcResultEntity> resultList) {
        if (boSaleInfo == null) return null;
        return BoSaleStoreStockResponse.builder()
                .code(boSaleInfo.getCode())
                .message(boSaleInfo.getMessage() == null ? "" : boSaleInfo.getMessage())
                .brandCd(boSaleInfo.getBrandCd() == null ? "" : boSaleInfo.getBrandCd())
                .storeNo(boSaleInfo.getStoreNo() == null ? "" : boSaleInfo.getStoreNo())
                .rSaleList(resultList.stream()
                        .map(m -> BoSaleStoreStockResponse.RsaleInfo.builder()
                                .menuCd(m.getMenuCd() == null ? "" : m.getMenuCd())
                                .itemId(m.getItemId() == null ? "" : m.getItemId())
                                .procCd(m.getProcCd() == null ? "" : m.getProcCd())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class RsaleInfo {
        @ApiModelProperty(value = "오더퀸 메뉴코드") private String menuCd;
        @ApiModelProperty(value = "품목아이디") private String itemId;
        @ApiModelProperty(value = "처리결과") private String procCd;  // 00 성공 , 01 품목없음, 02 실패
    }

}
