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 {

    private List<StoreItemUnitInfo> storeItemUnitList;


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

        return StoreItemUnitInfoResponse.builder()
                .storeItemUnitList(entities.stream()
                        .map(m -> StoreItemUnitInfo.builder()
                                .storeUnitUnqNo(m.getStoreUnitUnqNo())
                                .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())
                                .build())
                        .collect(Collectors.toList()))
                .build();
    }


    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class StoreItemUnitInfo {
        @ApiModelProperty(value = "매장단가고유번호")
        private String storeUnitUnqNo;

        @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 Integer unitAmt;

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

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

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






}
