package com.jwipc.inquiry.impl;

import com.jwipc.api.dto.ApiResult;
import com.jwipc.inquiry.client.PriceInfoClient;
import com.jwipc.inquiry.constant.FixOaClient;
import com.jwipc.inquiry.convert.PriceInfoClientConvert;
import com.jwipc.inquiry.dto.*;
import com.jwipc.inquiry.logic.PriceInfoLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/4/24 10:11
 * @desc
 */
@Service
@RequiredArgsConstructor
public class PriceInfoClientImpl implements PriceInfoClient {
    private final PriceInfoClientConvert priceInfoClientConvert;
    private final PriceInfoLogic priceInfoLogic;
    private final FixOaClient fixOaClient;

    /**
     * 生成价格信息记录
     *
     * @param list 信息记录
     * @return 结果
     */
    @Override
    public void createPriceInfo(List<CreatePriceInfoDTO> list) {
        priceInfoLogic.createPriceInfo(list);
    }

    /**
     * 根据物料编码和工厂获取历史最低价
     *
     * @return 历史最低价
     */
    @Override
    public HistoryPriceInfoDTO getHistoryLowPrice(String materialCode, String factoryCode) {
        return priceInfoLogic.getHistoryLowPrice(materialCode, factoryCode);
    }

    /**
     * 根据物料编码和工厂获取上次中标价
     *
     * @return 上次中标价
     */
    @Override
    public HistoryPriceInfoDTO getLastBidPrice(String materialCode, String factoryCode) {
        return priceInfoLogic.getLastBidPrice(materialCode, factoryCode);
    }

    /**
     * 根据物料编码和工厂和供应商编码获取最新价格信息记录
     *
     * @param materialCode 物料编码
     * @param factoryCode  工厂
     * @param supplierCode 供应商编码
     * @return 最新价格信息记录
     */
    @Override
    public PriceInfoClientDTO getLastPrice(String materialCode, String factoryCode, String supplierCode) {
        PriceInfoDTO priceInfoDTO = priceInfoLogic.getLastPrice(materialCode, factoryCode, supplierCode);

        return priceInfoClientConvert.dto2ClientDTO(priceInfoDTO);
    }

    @Override
    public List<PriceInfoClientDTO> getList(Collection<? extends Serializable> idList) {
        List<PriceInfoDTO> priceInfoDTOS = priceInfoLogic.getList(idList);
        return priceInfoClientConvert.dto2ClientDTOList(priceInfoDTOS);
    }

    @Override
    public PriceInfoClientDTO getById(Long id) {
        PriceInfoDTO priceInfoDTOS = priceInfoLogic.getById(id);
        return priceInfoClientConvert.dto2ClientDTO(priceInfoDTOS);
    }

    @Override
    public ApiResult<String> pushToOa(PriceImportCDTO priceImportCDTO) {
        PriceImportDTO priceImportDTO = priceInfoClientConvert.convert1(priceImportCDTO);
        return fixOaClient.priceImport(priceImportDTO);
    }


    @Override
    public List<PriceInfoClientDTO> getEffectiveMinPrice(List<String> materialCodes, Date date) {
        List<PriceInfoDTO> effectiveMinPrice = priceInfoLogic.getEffectiveMinPrice(materialCodes, date);
        return priceInfoClientConvert.dto2ClientDTOList(effectiveMinPrice);
    }


}
