package com.engine.salary.entity.salaryarchive.bo;

import com.engine.salary.entity.salaryarchive.dto.TaxAgentListDTO;
import com.engine.salary.entity.salaryarchive.param.TaxAgentSaveParam;
import com.engine.salary.entity.taxrate.TaxAgent;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 个税扣缴义务人
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class TaxAgentBO {

    @Override
    public String toString() {
        return "TaxAgentBO{}";
    }

    /**
     * 表数据转列表数据
     * @param individualTaxWithholdingAgents
     * @param tenantKey
     * @return
     */
    public static List<TaxAgentListDTO> convertToListDTO(Collection<TaxAgent> individualTaxWithholdingAgents, String tenantKey) {
        if (CollectionUtils.isEmpty(individualTaxWithholdingAgents)) {
            return Collections.emptyList();
        }
        return individualTaxWithholdingAgents.stream()
                .map(e -> TaxAgentListDTO.builder()
                        .id(e.getId())
                        .name(e.getName())
                        .description(e.getDescription())
                        .build())
                .collect(Collectors.toList());
    }

    /**
     * 保存参数转表数据
     * @param saveParam
     * @param employeeId
     * @param tenantKey
     * @return
     */
    public static TaxAgent convertToPO(TaxAgentSaveParam saveParam, Long employeeId, String tenantKey) {
        if (saveParam == null) {
            return null;
        }
        Date now = new Date();
        return TaxAgent.builder()
                .id(saveParam.getId())
                .name(saveParam.getName())
                .description(saveParam.getDescription())
                .createTime(now)
                .updateTime(now)
                .creator(employeeId)
                .tenantKey(tenantKey)
                .build();
    }
}
