package com.hzs.member.account.provider;

import com.hzs.common.core.domain.R;
import com.hzs.common.domain.member.account.CuMemberAccount;
import com.hzs.common.domain.member.ext.CuMemberAccountExt;
import com.hzs.common.domain.sale.order.SaOrder;
import com.hzs.member.account.IMemberAccountServiceApi;
import com.hzs.member.account.service.ICuMemberAccountService;
import com.hzs.member.base.service.ICuMemberBusinessService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description:
 * @Author: sui q
 * @Time: 2022/9/5 14:32
 * @Classname: MemberAccountServiceProvider
 * @PackageName: com.hzs.member.account.provider
 */
@Slf4j
@DubboService
public class MemberAccountServiceProvider implements IMemberAccountServiceApi {

    @Autowired
    private ICuMemberAccountService cuMemberAccountService;
    @Autowired
    private ICuMemberBusinessService iCuMemberBusinessService;

    @Override
    public R<List<CuMemberAccountExt>> queryMemberAccountByCondition(CuMemberAccount cuMemberAccount) {
        return R.ok(cuMemberAccountService.queryMemberAccountByCondition(cuMemberAccount));
    }

    @Override
    public R<List<CuMemberAccount>> queryCuMemberAccountByPkMembers(List<Long> pkMemberList) {
        return R.ok(cuMemberAccountService.queryCuMemberAccountByPkMembers(pkMemberList));
    }

    @Override
    public R orderChangeProductPre(SaOrder saOrder, SaOrder updateOrder) {
        try {
            String str = iCuMemberBusinessService.orderChangeProductPre(saOrder, updateOrder);
            if (null == str) {
                return R.ok();
            }
            return R.fail(str);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    @Override
    public R orderChangeProduct(SaOrder saOrder, SaOrder updateOrder, Long userId, Object obj) {
        try {
            iCuMemberBusinessService.orderChangeProduct(saOrder, updateOrder, userId, obj);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R orderReturn(SaOrder saOrder, Long userId, BigDecimal changeAmount, String changeRemark) {
        try {
            iCuMemberBusinessService.orderReturn(saOrder, userId, changeAmount, changeRemark);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R orderReturnMember(List<Long> pkMemberList, Long userId) {
        try {
            iCuMemberBusinessService.orderReturnMember(pkMemberList, userId);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R orderSelfDeliver(Long pkMember, Integer pkRate, Integer pkCountry, BigDecimal postage, Long userId) {
        try {
            String str = iCuMemberBusinessService.orderSelfDeliver(pkMember, pkRate, pkCountry, postage, userId);
            if (null != str) {
                return R.fail(str);
            }
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R insertMemberTrade(SaOrder saOrder, CuMemberAccountExt cuMemberAccount) {
        try {
            iCuMemberBusinessService.insertMemberTrade(saOrder, cuMemberAccount);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

}
