package com.hzs.system.common.provider;

import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.EAwards;
import com.hzs.common.core.enums.EGrade;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.domain.system.base.BdCountry;
import com.hzs.common.domain.system.base.BdCurrency;
import com.hzs.common.domain.system.config.BdAwards;
import com.hzs.common.domain.system.config.BdGrade;
import com.hzs.system.base.ICurrencyServiceApi;
import com.hzs.system.base.dto.CurrencyDTO;
import com.hzs.system.base.service.IBdCountryService;
import com.hzs.system.base.service.IBdCurrencyService;
import com.hzs.system.common.ICommonServiceApi;
import com.hzs.system.common.dto.MemberDataDTO;
import com.hzs.system.config.service.IBdAwardsService;
import com.hzs.system.config.service.IBdGradeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 公用dubbo接口
 * @Author: jiang chao
 * @Time: 2023/1/10 16:10
 * @Classname: CommonServiceProvider
 * @PackageName: com.hzs.system.common.provider
 */
@DubboService
public class CommonServiceProvider implements ICommonServiceApi {

    @Autowired
    private IBdCountryService iBdCountryService;
    @Autowired
    private IBdGradeService iBdGradeService;
    @Autowired
    private IBdAwardsService iBdAwardsService;
    @Autowired
    private IBdCurrencyService iBdCurrencyService;
    @Autowired
    private ICurrencyServiceApi iCurrencyServiceApi;

    @Override
    public R<MemberDataDTO> getMemberData(MemberDataDTO memberDataDTO) {

        // 自然国
        if (null != memberDataDTO.getPkCountry()) {
            BdCountry bdCountry = iBdCountryService.getCountry(memberDataDTO.getPkCountry());
            if (null != bdCountry) {
                memberDataDTO.setPkCountryVal(bdCountry.getShortName());
                memberDataDTO.setCountryCircularIcon(bdCountry.getNationalFlag1());
                memberDataDTO.setCountrySquareIcon(bdCountry.getNationalFlag2());
                memberDataDTO.setPkCountryTransaction(bdCountry.getPkTransaction());
            }
        }
        // 结算国
        if (null != memberDataDTO.getPkSettleCountry()) {
            BdCountry bdSettleCountry = iBdCountryService.getCountry(memberDataDTO.getPkSettleCountry());
            if (null != bdSettleCountry) {
                memberDataDTO.setPkSettleCountryVal(bdSettleCountry.getShortName());
                memberDataDTO.setSettleCountryCircularIcon(bdSettleCountry.getNationalFlag1());
                memberDataDTO.setSettleCountrySquareIcon(bdSettleCountry.getNationalFlag2());
                memberDataDTO.setSettleCountryLightName(bdSettleCountry.getLightName());
                memberDataDTO.setSettleCountryImg(bdSettleCountry.getImg());
                memberDataDTO.setPkSettleCountryTransaction(bdSettleCountry.getPkTransaction());
            }

            // 汇率
            CurrencyDTO currencyDTO = iCurrencyServiceApi.getCurrency(memberDataDTO.getPkSettleCountry()).getData();
            memberDataDTO.setExchangeRate(currencyDTO.getInExchangeRate());
        }

        // 等级
        if (null != memberDataDTO.getPkGrade()) {
            BdGrade bdGrade = iBdGradeService.getBdGrade(memberDataDTO.getPkGrade());
            if (null != bdGrade) {
                memberDataDTO.setPkGrade(bdGrade.getPkTransaction());
                memberDataDTO.setGradeValue(bdGrade.getGradeValue());
                memberDataDTO.setGradeIcon(bdGrade.getImage());
                if (EGrade.START_UP.getValue() == bdGrade.getGradeValue()) {
                    memberDataDTO.setMemberGrade(EYesNo.YES.getIntValue());
                } else {
                    memberDataDTO.setMemberGrade(EYesNo.NO.getIntValue());
                }
            }
        }
        // 奖衔
        if (null != memberDataDTO.getPkAwards()) {
            BdAwards bdAwards = iBdAwardsService.getBdAwardsOne(memberDataDTO.getPkAwards());
            if (null != bdAwards) {
                memberDataDTO.setPkAwards(bdAwards.getPkTransaction());
                if (EAwards.MEMBER.getValue() != bdAwards.getAwardsValue()) {
                    // 奖衔如果是会员级别不返回图标
                    memberDataDTO.setAwardsIcon(bdAwards.getImage());
                }
            }
        }
        // 币种
        if (null != memberDataDTO.getPkSettleCountry()) {
            BdCurrency bdCurrency = iBdCurrencyService.getCurrency(memberDataDTO.getPkSettleCountry());
            if (null != bdCurrency) {
                memberDataDTO.setCurrencyIcon(bdCurrency.getSymbol());
            }
        }

        return R.ok(memberDataDTO);
    }

}
