package com.oqpo.api.web.dto.response.stinfo.itemUnit;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.FileEntity;
import com.oqpo.api.entity.stinfo.ItemUnitEntity;
import com.oqpo.api.entity.stinfo.StoreItemUnitEntity;
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 StoreItemUnitInfoResponse {

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

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

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

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


    public static StoreItemUnitInfoResponse toDTO(List<StoreItemUnitEntity> entities) {
        if (entities == null) return null;

        return StoreItemUnitInfoResponse.builder()
                .gridPage(0)
                .gridRecords(entities.size())
                .gridTotal(0)
                .gridRows(entities.stream()
                        .map(m -> StoreItemUnitInfoData.builder()
                                .viewCd(m.getViewCd())
                                .viewNm("C".toString().equals(m.getViewCd()) ? "추가" : "" )
                                .storeUnitUnqNo(m.getStoreUnitUnqNo() == null ? "" :m.getStoreUnitUnqNo())
                                .brandUnitUnqNo(m.getBrandUnitUnqNo() == null ? "" :m.getBrandUnitUnqNo())
                                .brandId(m.getBrandId())
                                .itemId(m.getItemId())
                                .itemNm(m.getItemNm())
                                .contSttDt(m.getContSttDt() == null ? "" :m.getContSttDt())
                                .contEndDt(m.getContEndDt() == null ? "" :m.getContEndDt())
                                .unit(m.getUnit() == null ? "" :m.getUnit())
                                .unitNm(m.getUnitNm() == null ? "" :m.getUnitNm())
                                .stddQty(m.getStddQty() == null ? 0 :m.getStddQty() )
                                .curr(m.getCurr() == null ? "" :m.getCurr())
                                .currNm(m.getCurrNm() == null ? "" :m.getCurrNm())
                                .unitAmt(m.getUnitAmt() == null ? 0 :m.getUnitAmt())
                                .unitTargetCd(m.getUnitTargetCd() == null ? "" :m.getUnitTargetCd())
                                .unitTargetNm(m.getUnitTargetNm() == null ? "" :m.getUnitTargetNm())
                                .spplyUnitAmt (m.getSpplyUnitAmt() == null ? 0 :m.getSpplyUnitAmt())
                                .spplyId(m.getSpplyId() == null ? "" : m.getSpplyId())
                                .spplyNm(m.getSpplyNm() == null ? "" : m.getSpplyNm())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }


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

        @ApiModelProperty(value = "작업구분")
        private String viewCd;

        @ApiModelProperty(value = "작업구분명")
        private String viewNm;

        @ApiModelProperty(value = "매장단가고유번호")
        private String storeUnitUnqNo;

        @ApiModelProperty(value = "브랜드 단가고유번호")
        private String brandUnitUnqNo;

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

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

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

        @ApiModelProperty(value = "계약시작일자")
        private String contSttDt;

        @ApiModelProperty(value = "계약종료일자")
        private String contEndDt;

        @ApiModelProperty(value = "단위")
        private String unit;

        @ApiModelProperty(value = "단위명")
        private String unitNm;

        @ApiModelProperty(value = "기준수량")
        private Integer stddQty;

        @ApiModelProperty(value = "통화")
        private String curr;

        @ApiModelProperty(value = "통화명")
        private String currNm;

        @ApiModelProperty(value = "단가금액")
        private Long unitAmt;

        @ApiModelProperty(value = "대상여부")
        private String unitTargetCd;

        @ApiModelProperty(value = "대상여부명")
        private String unitTargetNm;

        @ApiModelProperty(value = "공급사단가")
        private Long spplyUnitAmt ;

        @ApiModelProperty(value = "공급사")
        private String spplyId ;

        @ApiModelProperty(value = "공급사명")
        private String spplyNm ;
    }






}
