package cn.superdesk.uniorder.dubbo.provider.unified.settlement;

import cn.superdesk.uniorder.common.enums.accounting.operator.SettlementRuleEnum;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.unified.settlement.UnifiedSettlementProgramme;
import cn.superdesk.uniorder.dto.param.operationCenter.customer.OperationCenterCustomerParam;
import cn.superdesk.uniorder.dto.param.operationCenter.customer.settlement.UnifiedSettlementParam;
import cn.superdesk.uniorder.dto.vo.operationCenter.customer.OperationCenterCustomerVo;
import cn.superdesk.uniorder.dto.vo.operationCenter.customer.settlement.UnifiedSettlementVo;
import cn.superdesk.uniorder.dubbo.facade.unified.settlement.DubboUnifiedSettlementProgrammeService;
import cn.superdesk.uniorder.service.unified.settlement.UnifiedSettlementProgrammeService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

@Service(version = "1.0.1", retries = -1, timeout = 10000)
public class DubboUnifiedSettlementProgrammeServiceImpl implements DubboUnifiedSettlementProgrammeService {
    @Autowired
    UnifiedSettlementProgrammeService unifiedSettlementProgrammeService;
    @Override
    public UnifiedSettlementProgramme findById(Long id) {
        return unifiedSettlementProgrammeService.findById(id);
    }

    @Override
    public R<String> saveUnifiedSettlement(UnifiedSettlementParam param, Long sysUserId) {
        return unifiedSettlementProgrammeService.saveUnifiedSettlement(param, sysUserId);
    }

    @Override
    public R<String> updateUnifiedSettlement(UnifiedSettlementParam param, Long sysUserId) {
        return unifiedSettlementProgrammeService.updateUnifiedSettlement(param, sysUserId);
    }

    @Override
    public R<List<UnifiedSettlementVo>> list(OperationCenterCustomerParam param) {
        PageHelper.startPage(param.getPageNumber(), param.getPageNumber());

        List<UnifiedSettlementVo> list = unifiedSettlementProgrammeService.list(param);

       list= list.stream().map(vo->{
            vo.setSettlementRuleDesc(vo.getSettlementRule()!=null ? SettlementRuleEnum.getDescByKey(vo.getSettlementRule()) :"" );
            return vo;
        }).collect(Collectors.toList());

        PageInfo page = new PageInfo(list);

        return new R<List<UnifiedSettlementVo>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), list);
    }

    @Override
    public R<UnifiedSettlementParam> get(Long id) {
        return unifiedSettlementProgrammeService.get(id);
    }

}
