package com.engine.salary.wrapper;

import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationDetailListQueryParam;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO;
import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
import com.engine.salary.service.TaxDeclarationDetailService;
import com.engine.salary.service.TaxDeclarationService;
import com.engine.salary.service.impl.TaxDeclarationDetailServiceImpl;
import com.engine.salary.service.impl.TaxDeclarationServiceImpl;
import com.engine.salary.util.page.PageInfo;
import lombok.extern.slf4j.Slf4j;
import weaver.hrm.User;

import java.util.Objects;


/**
 * 个税申报表明细
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
@Slf4j
public class TaxDeclarationDetailWrapper extends Service {

    private TaxDeclarationDetailService getTaxDeclarationDetailService(User user) {
        return ServiceUtil.getService(TaxDeclarationDetailServiceImpl.class, user);
    }

    private TaxDeclarationService getTaxDeclarationService(User user) {
        return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
    }

    /**
     * 个税申报表明细列表
     *
     * @param queryParam 列表查询条件
     * @return
     */
    public PageInfo listPage(TaxDeclarationDetailListQueryParam queryParam) {

        TaxDeclarationPO taxDeclarationPO = getTaxDeclarationService(user).getById(queryParam.getTaxDeclarationId());


        // 正常工资薪金所得
        if (Objects.equals(taxDeclarationPO.getIncomeCategory(), IncomeCategoryEnum.WAGES_AND_SALARIES.getValue())) {
            return getTaxDeclarationDetailService(user).listDtoPageByParam4Wage(queryParam);
        }
        // 劳务报酬所得
        if (Objects.equals(taxDeclarationPO.getIncomeCategory(), IncomeCategoryEnum.REMUNERATION_FOR_LABOR.getValue())) {
            return getTaxDeclarationDetailService(user).listDtoPageByParam4Labor(queryParam);
        }

        // 全年一次性奖金收入
        if (Objects.equals(taxDeclarationPO.getIncomeCategory(), IncomeCategoryEnum.ONETIME_ANNUAL_BONUS.getValue())) {
            return getTaxDeclarationDetailService(user).listDtoPageByParam4Annual(queryParam);
        }

        return new PageInfo();
    }
}
