package cn.superdesk.uniorder.dubbo.consumer.operationCenter.base;

import cn.superdesk.data.extract.enums.opCenter.*;
import cn.superdesk.uniorder.common.enums.accounting.operator.AccountingEmailStatusEnum;
import cn.superdesk.uniorder.common.enums.accounting.operator.AccountingOrderOperatorAccountStatusEnum;
import cn.superdesk.uniorder.common.enums.common.CommonAccountingStateEnum;
import cn.superdesk.uniorder.common.enums.common.CommonSettlementStateEnum;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dto.param.operationCenter.base.OperationCenterParam;
import cn.superdesk.uniorder.dto.vo.operationCenter.base.OperationCenterVo;
import cn.superdesk.uniorder.dto.vo.sys.SysSelectVo;
import cn.superdesk.uniorder.dubbo.facade.operationCenter.customer.DubboOperationCenterCustomerService;
import cn.superdesk.uniorder.dubbo.facade.operationCenter.payment.DubboOperationCenterPaymentService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author : zx
 * @Create : 2023/3/28 10:49
 * Description : 提供服务
 */
@Slf4j
@Component
public class OperationCenterBaseDubboService {
    @Reference(version = "1.0.0", timeout = 30000, retries = -1)
    private DubboOperationCenterPaymentService dubboOperationCenterPaymentService;

    @Reference(version = "1.0.0", timeout = 30000, retries = -1)
    private DubboOperationCenterCustomerService dubboOperationCenterCustomerService;

    public List<OperationCenterVo> getPlatformCode() {
        List<OperationCenterVo> platformList = new ArrayList<>();

        for (OpCenterBizPlatformEnum platformEnum : OpCenterBizPlatformEnum.values()) {
            OperationCenterVo vo =new OperationCenterVo();
            vo.setCode(platformEnum.getCode());
            vo.setName(platformEnum.getName());
            platformList.add(vo);
        }
        return platformList;
    }

    public List<OperationCenterVo> getOrderType() {
        List<OperationCenterVo> orderTypeList = new ArrayList<>();

        for (OpCenterOrderTypeEnum orderTypeVo : OpCenterOrderTypeEnum.values()) {
            if ("FLSC".equals(orderTypeVo.getCode()) || "FZS".equals(orderTypeVo.getCode())) {
                OperationCenterVo vo = new OperationCenterVo();
                vo.setCode(orderTypeVo.getCode());
                vo.setName(orderTypeVo.getName());
                orderTypeList.add(vo);
            }
        }
        return orderTypeList;
    }


    public List<OperationCenterVo> getOrderBizType() {
        List<OperationCenterVo> orderBizType = new ArrayList<>();

        for (OpCenterOrderBizTypeEnum orderBizTypeVo : OpCenterOrderBizTypeEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(orderBizTypeVo.getCode().toString());
            vo.setName(orderBizTypeVo.getDesc());
            orderBizType.add(vo);
        }
        return orderBizType;
    }

    public List<OperationCenterVo> getOrderPayStatus() {
        List<OperationCenterVo> orderPayStatus = new ArrayList<>();

        for (OpCenterOrderPayStatusEnum orderPayStatusVo : OpCenterOrderPayStatusEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(orderPayStatusVo.getCode().toString());
            vo.setName(orderPayStatusVo.getDesc());
            orderPayStatus.add(vo);
        }
        return orderPayStatus;
    }

    public List<OperationCenterVo> getTransactionStatus() {
        List<OperationCenterVo> transactionStatus = new ArrayList<>();

        for (OpCenterTransactionStatusEnum transactionStatusVo : OpCenterTransactionStatusEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(transactionStatusVo.getCode().toString());
            vo.setName(transactionStatusVo.getDesc());
            transactionStatus.add(vo);
        }
        return transactionStatus;

    }

    public List<OperationCenterVo> getAfterSaleStatus() {
        List<OperationCenterVo> afterSaleStatus = new ArrayList<>();

        for (OpCenterPlatformAftersaleStatusEnum afterSaleStatusVo : OpCenterPlatformAftersaleStatusEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(afterSaleStatusVo.getCode().toString());
            vo.setName(afterSaleStatusVo.getDesc());
            afterSaleStatus.add(vo);
        }
        return afterSaleStatus;
    }

    public List<OperationCenterVo> getAfterSaleType() {
        List<OperationCenterVo> afterSaleType = new ArrayList<>();

        for (OpCenterPlatformAftersaleTypeEnum afterSaleTypeVo : OpCenterPlatformAftersaleTypeEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(afterSaleTypeVo.getCode().toString());
            vo.setName(afterSaleTypeVo.getDesc());
            afterSaleType.add(vo);
        }
        return afterSaleType;
    }

    public List<OperationCenterVo> getPaymentByCustomerId(Long customerId) {
        return dubboOperationCenterPaymentService.getPaymentByCustomerId(customerId);
    }


    /**
     * 运营中心--项目下拉列表
     */
    public R<List<SysSelectVo>> selectOrgList(OperationCenterParam param) {
        return dubboOperationCenterCustomerService.selectOrgList(param);
    }

    /**
     * 商品类型：商品/运费
     */
    public List<OperationCenterVo> getOrderGoodType() {

        List<OperationCenterVo> orderGoodType = new ArrayList<>();

        for (OpCenterGoodsTypeEnum orderGoodTypeVo : OpCenterGoodsTypeEnum.values()) {
            if (orderGoodTypeVo.getCode().intValue() == OpCenterGoodsTypeEnum.商品.getCode()
                    || orderGoodTypeVo.getCode().intValue() == OpCenterGoodsTypeEnum.运费.getCode()) {
                OperationCenterVo vo = new OperationCenterVo();
                vo.setCode(orderGoodTypeVo.getCode().toString());
                vo.setName(orderGoodTypeVo.getDesc());
                orderGoodType.add(vo);
            }

        }
        return orderGoodType;
    }
    /**
     *   对账状态：未对账/对账中/已对账
     */
    public List<OperationCenterVo> getAccountingState() {

        List<OperationCenterVo> accountingState = new ArrayList<>();

        for (CommonAccountingStateEnum value : CommonAccountingStateEnum.values()) {
            if (value.getKey().intValue() == CommonAccountingStateEnum.未对账.getKey()
                    || value.getKey().intValue() == CommonAccountingStateEnum.对账中.getKey()
                    || value.getKey().intValue() == CommonAccountingStateEnum.已对账.getKey()) {
                OperationCenterVo vo = new OperationCenterVo();
                vo.setCode(value.getKey().toString());
                vo.setName(value.getDesc());
                accountingState.add(vo);
            }
        }
        return accountingState;
    }


    /**
     *   账单状态 //1-生成中,2-待提交,3-未确认,4-已确认,5-已驳回,6-已取消,7-已作废
     */
    public List<OperationCenterVo> opAccountingStatus(Integer type) {

        List<OperationCenterVo> accountingState = new ArrayList<>();

        for (AccountingOrderOperatorAccountStatusEnum value : AccountingOrderOperatorAccountStatusEnum.values()) {
            if(!type.equals(value.getType())){
                continue;
            }
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(value.getKey().toString());
            vo.setName(value.getDesc());
            accountingState.add(vo);
        }
        return accountingState;
    }
    /**
     *  是否参与结算//1, "未结算" 2,"结算" 3, "不结算"
     */
    public List<OperationCenterVo> getIsSettlement() {
        List<OperationCenterVo> isSettlementResult = new ArrayList<>();

        for (CommonSettlementStateEnum isSettlement : CommonSettlementStateEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(isSettlement.getKey().toString());
            vo.setName(isSettlement.getDesc());
            isSettlementResult.add(vo);
        }
        return isSettlementResult;

    }

    /**
     *   邮件状态 AccountingEmailStatusEnum
     */
    public List<OperationCenterVo> emailStatus() {
        List<OperationCenterVo> accountingState = new ArrayList<>();
        for (AccountingEmailStatusEnum value : AccountingEmailStatusEnum.values()) {
            OperationCenterVo vo = new OperationCenterVo();
            vo.setCode(value.getKey().toString());
            vo.setName(value.getDesc());
            accountingState.add(vo);
        }
        return accountingState;
    }
}
