package com.jwipc.sys.client.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwipc.sys.client.TaxClient;
import com.jwipc.sys.client.dto.TaxDTO;
import com.jwipc.sys.client.convert.TaxClientConvert;
import com.jwipc.sys.entity.TaxInfo;
import com.jwipc.sys.service.ITaxService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Service
@RequiredArgsConstructor
public class TaxClientImpl implements TaxClient {
    private final ITaxService taxService;
    private final TaxClientConvert taxClientConvert;

    public TaxDTO getByCode(String code){
        final TaxInfo one = taxService.getOne(new LambdaQueryWrapper<TaxInfo>().eq(TaxInfo::getTaxCode, code));
        return taxClientConvert.entity2Dto(one);
    }

    public List<TaxDTO> getAll(){
        final List<TaxInfo> one = taxService.list();
        return taxClientConvert.entities2Dtos(one);
    }

    public List<TaxDTO> getTaxList(Collection<? extends Serializable> codeList) {
        if (CollUtil.isEmpty(codeList)) {
            return Collections.emptyList();
        }
        final List<TaxInfo> list = taxService.list(new LambdaQueryWrapper<TaxInfo>().in(TaxInfo::getTaxCode, codeList));
        return taxClientConvert.entities2DTOs(list);
    }
}
