package com.hzs.system.base.provider;

import cn.hutool.core.bean.BeanUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.EDelayBusType;
import com.hzs.common.domain.system.base.BdCountry;
import com.hzs.system.base.ICountryServiceApi;
import com.hzs.system.base.dto.CountryDTO;
import com.hzs.system.base.service.IBdCountryService;
import com.hzs.system.base.service.IBdCurrencyService;
import com.hzs.system.config.service.IBdAccountService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 国家dubbo服务
 */
@DubboService
public class CountryServiceProvider implements ICountryServiceApi {

    @Autowired
    private IBdCountryService iBdCountryService;
    @Autowired
    private IBdCurrencyService iBdCurrencyService;
    @Autowired
    private IBdAccountService iBdAccountService;

    @Override
    public R<CountryDTO> getCountry(Integer countryId) {
        BdCountry bdCountry = iBdCountryService.getCountry(countryId);
        if (null == bdCountry) {
            return R.fail();
        }
        return R.ok(BeanUtil.copyProperties(bdCountry, CountryDTO.class));
    }

    @Override
    public R<Map<Integer, BdCountry>> getAllCountryMap() {
        return R.ok(iBdCountryService.getAllCountryMap());
    }

    @Override
    public R<Boolean> updateConfigEffectById(Integer businessType, Integer pkId) {
        if (EDelayBusType.COUNTRY.getValue() == businessType) {
            iBdCountryService.updateCountryId(pkId);
        } else if (EDelayBusType.CURRENCY.getValue() == businessType) {
            iBdCurrencyService.updateCurrencyById(pkId);
        } else if (EDelayBusType.ACCOUNT.getValue() == businessType) {
            iBdAccountService.updateAccountById(pkId);
        }
        return R.ok();
    }
}
