package com.zanxiang.game.module.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zanxiang.game.module.manage.pojo.dto.PayWayDTO;
import com.zanxiang.game.module.manage.pojo.vo.PayWayChoiceVO;
import com.zanxiang.game.module.manage.service.IPayWayService;
import com.zanxiang.game.module.mybatis.entity.PayWay;
import com.zanxiang.game.module.mybatis.mapper.PayWayMapper;
import com.zanxiang.module.util.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author : lingfeng
 * @time : 2023-02-09
 * @description : 支付渠道
 */
@Service
@Slf4j
public class PayWayServiceImpl extends ServiceImpl<PayWayMapper, PayWay> implements IPayWayService {

    @Override
    public List<PayWayChoiceVO> payWayChoiceList() {
        List<PayWay> payWayList = super.list(new LambdaQueryWrapper<PayWay>()
                .select(PayWay::getId, PayWay::getPayWayName)
        );
        List<PayWayChoiceVO> payWayChoiceVOList = new ArrayList<>();
        payWayList.forEach(payWay -> payWayChoiceVOList.add(PayWayChoiceVO.builder()
                .id(payWay.getId())
                .payName(payWay.getPayWayName())
                .build()));
        return payWayChoiceVOList;
    }

    @Override
    public Map<Long, PayWayDTO> payWayMap() {
        //查询
        List<PayWay> payWayList = super.list();
        if (CollectionUtils.isEmpty(payWayList)) {
            return Collections.emptyMap();
        }
        return payWayList.stream().map(payWay -> BeanUtil.copy(payWay, PayWayDTO.class))
                .collect(Collectors.toMap(PayWayDTO::getId, Function.identity()));
    }
}
