/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.api.vo.MerchantIncomeVO;
import org.springblade.modules.system.entity.UserMerchant;
import org.springblade.modules.system.mapper.UserMerchantMapper;
import org.springblade.modules.system.service.IUserMerchantService;
import org.springblade.modules.system.vo.UserMerchantVO;
import org.springblade.modules.system.wrapper.UserMerchantWrapper;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 商家用户表 服务实现类
 *
 * @author BladeX
 * @since 2024-07-16
 */
@Service
public class UserMerchantServiceImpl extends ServiceImpl<UserMerchantMapper, UserMerchant> implements IUserMerchantService {

	@Override
	public IPage<UserMerchantVO> selectUserMerchantPage(IPage<UserMerchantVO> page, UserMerchantVO userMerchant) {
		return page.setRecords(baseMapper.selectUserMerchantPage(page, userMerchant));
	}

	@Override
	public UserMerchantVO getByUserId(Long userId) {
		UserMerchant one = getOne(Wrappers.lambdaQuery(UserMerchant.class).eq(UserMerchant::getUserId, userId));
		return UserMerchantWrapper.build().entityVO(one);
	}

	@Override
	public List<Long> getAuthShopId(Long userId) {
		UserMerchant one = getOne(Wrappers.lambdaQuery(UserMerchant.class).eq(UserMerchant::getUserId, userId));
		if(Objects.isNull(one)){
            return new ArrayList<>();
		}
		if(Objects.isNull(one.getAuthShop())){
			return new ArrayList<>();
		}
		String[] split = one.getAuthShop().split(",");
		List<Long> ids = new ArrayList<>();
		for (String s : split) {
			ids.add(Long.parseLong(s));
		}
		return ids;
	}

	@Override
	public IPage<MerchantIncomeVO> pageIncome(IPage<MerchantIncomeVO> page, Long userId) {
		return page.setRecords(baseMapper.pageIncome(page, userId));
	}

	@Override
	public Map<String, String> getCash() {
		//获取我的可提现金额
		Map<String, String> result = new HashMap<>();
		result.put("cash", "6469.98");
		return result;
	}

}
