package com.hzs.activity.base.provider;

import cn.hutool.core.bean.BeanUtil;
import com.hzs.activity.base.IActivityServiceApi;
import com.hzs.activity.base.service.IActivityService;
import com.hzs.activity.draw.service.IAcDrawRewardNumService;
import com.hzs.activity.dto.AcRecommendUpgradeDTO;
import com.hzs.activity.recommend.dto.AcRecommendUpgrade;
import com.hzs.activity.recommend.service.IAcRepurCouponsRuleConfigService;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.sale.ext.SaOrderExt;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 所有活动的生效，获得赠品入口
 */
@Slf4j
@DubboService
public class ActivityServiceProvider implements IActivityServiceApi {

    @Autowired
    private IAcDrawRewardNumService iAcDrawRewardNumService;
    @Autowired
    private IAcRepurCouponsRuleConfigService iAcRepurCouponsRuleConfigService;
    @Autowired
    private IActivityService iActivityService;

    @Override
    public R<Boolean> handleActivity(SaOrderExt saOrderExt) {
        try {
            return R.ok(iActivityService.handleActivity(saOrderExt));
        } catch (Exception e) {
            return R.fail();
        }
    }

    @Override
    public R<Boolean> backGiveMemberDrawNum(SaOrderExt saOrderExt) {
        try {
            return R.ok(iAcDrawRewardNumService.backGiveMemberDrawNum(saOrderExt));
        } catch (Exception e) {
            return R.fail();
        }
    }

    @Override
    public R<Boolean> invokeRecommendUpgrade(AcRecommendUpgradeDTO recommendUpgradeDTO) {
        try {
            return R.ok(iAcRepurCouponsRuleConfigService.invokeRecommendUpgrade(BeanUtil.copyProperties(recommendUpgradeDTO, AcRecommendUpgrade.class)));
        } catch (Exception e) {
            return R.fail();
        }
    }

}
