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

import com.oqpo.api.entity.stinfo.SpplyMgrEntity;
import com.oqpo.api.entity.stinfo.StoreItemUnitEntity;
import com.oqpo.api.web.dto.request.stinfo.spply.SaveSpplyRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class SaveStoreItemUnitInfolRequest {

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

    @ApiModelProperty(value = "매장아이디")
    private String storeId;

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

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

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


    @ApiModelProperty(value = "매장단가정보리스트")
    private List<SaveStoreItemUnitInfolRequest.SaveStoreItemUnit> gridUpdateData;


    public List<StoreItemUnitEntity> toCodeEntities(List< SaveStoreItemUnitInfolRequest.SaveStoreItemUnit > gridData) {
        List<StoreItemUnitEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;

        gridData.forEach(x -> {
            StoreItemUnitEntity entity = new StoreItemUnitEntity();
            entity.setStoreUnitUnqNo(x.getStoreUnitUnqNo());
            entity.setUnit(x.getUnit());
            entity.setCurr(x.getCurr());
            entity.setUnitAmt(x.getUnitAmt());
            entity.setShortContFileNo(x.getShortContFileNo());
            entity.setUnitTargetCd(x.getUnitTargetCd());
            entity.setItemId(x.getItemId());
            entity.setStddQty(x.getStddQty());
            entity.setBrandUnitUnqNo(x.getBrandUnitUnqNo());
            entities.add(entity);
        });
        return entities;
    }

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

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

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

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

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

        @ApiModelProperty(value = "계약문서첨부파일번호")
        private String shortContFileNo;

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

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

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

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