package com.friday.custody.service.trustService.mailHandleService.multiVersionService.impl;

import com.friday.custody.dto.TenantEscrowAuthorizationInfoDto;
import com.friday.custody.service.basicService.TenantEmailVersionMapService;
import com.friday.custody.service.trustService.mailHandleService.multiVersionService.IHandlerTxtService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.io.File;

/**
 * @Description
 * @Author k0051745
 * @Date: 2022/11/21
 */
@Service
@Slf4j
public class BaseHandlerTxtServiceImpl implements IHandlerTxtService {
    @Autowired
    TenantEmailVersionMapService tenantEmailVersionMapService;

    public String getTenantEmailVersionMapService(String trustNo) {
        String version = tenantEmailVersionMapService.getVersionByTrustNo(trustNo);
        if (!ObjectUtils.isEmpty(version)){
            return version;
        }
        return null;
    }

    @Autowired
    HandlerVersionTxtServiceImpl handler372VersionTxtService;

    public static final String VERSION_372 = "3.72";
    public static final String VERSION_400 = "4.00";
    public static final String VERSION_410 = "4.10";

    @Override
    public IHandlerTxtService getHandlerTxtService(String version) {
//        log.info("BaseHandlerTxtServiceImpl:getHandlerTxtService:version={}",version);
//        switch (version){
//            case VERSION_400:
//                log.info("BaseHandlerTxtServiceImpl:getHandlerTxtService:version={},选择【handler400VersionTxtService】",version);
//                return handler400VersionTxtService;
//            case VERSION_410:
//                log.info("BaseHandlerTxtServiceImpl:getHandlerTxtService:version={},选择【handler410VersionTxtService】",version);
//                return handler410VersionTxtService;
//            case VERSION_372:
//                log.info("BaseHandlerTxtServiceImpl:getHandlerTxtService:version={},选择【handler410VersionTxtService】",version);
//                return handler372VersionTxtService;
//        }
//        log.error("BaseHandlerTxtServiceImpl:getHandlerTxtService:version{} 没有匹配的service",version);
        return null;
    }

    /**
     * 全量更新
     *  @param tenant
     * @param file
     * @param flag
     * @param version
     */
    @Override
    public void getAllData(TenantEscrowAuthorizationInfoDto tenant, File file, String flag, String version) {
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        handlerTxtService.getAllData(tenant,file, flag, version);
    }

    /**
     * 每日更新
     *  @param tenant
     * @param file
     * @param flag
     * @param version
     */
    @Override
    public void getUpdateData(TenantEscrowAuthorizationInfoDto tenant, File file, String flag, String version) {
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        handlerTxtService.getUpdateData(tenant,file, flag, version);
    }

    /**
     * 1 基金产品信息表（fund_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processFundInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processFundInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processFundInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 2 基金出资人信息表（investor_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processInvestorInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processInvestorInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processInvestorInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 2 基金出资人信息表（investeor_bank_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processInvestorBankInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processInvestorBankInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processInvestorBankInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 4 基金持有信息表（cust_share_detail_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processCustShareDetailInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processCustShareDetailInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processCustShareDetailInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 18 基金交易确认信息表（fund_trade_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processFundTradeInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processFundTradeInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processFundTradeInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 17 托管⼾流⽔表（custShare_seq_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processCustShareSeqInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processCustShareSeqInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processCustShareSeqInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 14 业绩报酬信息表(fund_profit_info)
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processFundProfitInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processFundProfitInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processFundProfitInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 3 基金净值信息表（fund_net_value_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processFundNetValueInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processFundNetValueInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processFundNetValueInfoData(tenant,file, trustNo,flag, version);
    }

    /**
     * 4 基金持有信息表（cust_share_info）
     *  @param tenant
     * @param file
     * @param trustNo
     * @param flag
     * @param version
     */
    @Override
    public void processCustShareInfoData(TenantEscrowAuthorizationInfoDto tenant, File file, String trustNo, String flag, String version) {
        log.info("BaseHandlerTxtServiceImpl:processCustShareInfoData:version={}",version);
        IHandlerTxtService handlerTxtService = getHandlerTxtService(version);
        log.info("选择的service为{}",handlerTxtService.getClass());
        handlerTxtService.processCustShareInfoData(tenant,file, trustNo,flag, version);
    }
}
