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.PayDeviceDTO;
import com.zanxiang.game.module.manage.pojo.vo.PayDeviceChoiceVO;
import com.zanxiang.game.module.manage.service.IPayDeviceService;
import com.zanxiang.game.module.mybatis.entity.PayDevice;
import com.zanxiang.game.module.mybatis.mapper.PayDeviceMapper;
import com.zanxiang.module.util.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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 PayDeviceServiceImpl extends ServiceImpl<PayDeviceMapper, PayDevice> implements IPayDeviceService {

    @Override
    public List<PayDeviceChoiceVO> payDeviceChoiceList() {
        List<PayDevice> payDeviceList = super.list(new LambdaQueryWrapper<PayDevice>()
                .select(PayDevice::getId, PayDevice::getPayWayIds, PayDevice::getPayDeviceName)
        );
        return payDeviceList.stream().map(payDevice -> BeanUtil.copy(payDevice, PayDeviceChoiceVO.class))
                .collect(Collectors.toList());
    }

    @Override
    public Map<Long, PayDeviceDTO> payDeviceMap() {
        List<PayDevice> payDeviceList = super.list();
        if (CollectionUtils.isEmpty(payDeviceList)) {
            return Collections.emptyMap();
        }
        return payDeviceList.stream().map(payDevice -> BeanUtil.copy(payDevice, PayDeviceDTO.class))
                .collect(Collectors.toMap(PayDeviceDTO::getId, Function.identity()));
    }
}
