package beilv.voucher.service.impl;

import java.util.List;
import java.util.Map;

import beilv.common.utils.DictUtils;
import beilv.usermembershipcard.domain.UserMembershipCard;
import beilv.voucher.domain.BeilvVoucher;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import beilv.voucher.mapper.BeilvVoucherMemberMapper;
import beilv.voucher.domain.BeilvVoucherMember;
import beilv.voucher.service.IBeilvVoucherMemberService;
import beilv.common.core.text.Convert;

/**
 * 代金券用户关系Service业务层处理
 *
 * @author ruoyi
 * @date 2025-11-20
 */
@Service
public class BeilvVoucherMemberServiceImpl implements IBeilvVoucherMemberService {
    @Autowired
    private BeilvVoucherMemberMapper beilvVoucherMemberMapper;

    /**
     * 查询代金券用户关系
     *
     * @param id 代金券用户关系主键
     * @return 代金券用户关系
     */
    @Override
    public BeilvVoucherMember selectBeilvVoucherMemberById(Long id) {
        return beilvVoucherMemberMapper.selectBeilvVoucherMemberById(id);
    }

    /**
     * 查询代金券用户关系列表
     *
     * @param beilvVoucherMember 代金券用户关系
     * @return 代金券用户关系
     */
    @Override
    public List<BeilvVoucherMember> selectBeilvVoucherMemberList(BeilvVoucherMember beilvVoucherMember) {
        return beilvVoucherMemberMapper.selectBeilvVoucherMemberList(beilvVoucherMember);
    }

    /**
     * 新增代金券用户关系
     *
     * @param beilvVoucherMember 代金券用户关系
     * @return 结果
     */
    @Override
    public int insertBeilvVoucherMember(BeilvVoucherMember beilvVoucherMember) {
        return beilvVoucherMemberMapper.insertBeilvVoucherMember(beilvVoucherMember);
    }

    /**
     * 修改代金券用户关系
     *
     * @param beilvVoucherMember 代金券用户关系
     * @return 结果
     */
    @Override
    public int updateBeilvVoucherMember(BeilvVoucherMember beilvVoucherMember) {
        return beilvVoucherMemberMapper.updateBeilvVoucherMember(beilvVoucherMember);
    }

    /**
     * 批量删除代金券用户关系
     *
     * @param ids 需要删除的代金券用户关系主键
     * @return 结果
     */
    @Override
    public int deleteBeilvVoucherMemberByIds(String ids) {
        return beilvVoucherMemberMapper.deleteBeilvVoucherMemberByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除代金券用户关系信息
     *
     * @param id 代金券用户关系主键
     * @return 结果
     */
    @Override
    public int deleteBeilvVoucherMemberById(Long id) {
        return beilvVoucherMemberMapper.deleteBeilvVoucherMemberById(id);
    }

    /**
     * APP端查询代金券列表
     * @param beilvVoucherMember
     * @return
     */
    @Override
    public List<BeilvVoucherMember> selectAppVoucherList(BeilvVoucherMember beilvVoucherMember) {
        List<BeilvVoucherMember> voucherMemberList = beilvVoucherMemberMapper.selectAppVoucherList(beilvVoucherMember);
        Map<String, String> voucherType = DictUtils.getDictCacheToMap("voucher_type");
        Map<String, String> isValidity = DictUtils.getDictCacheToMap("is_validity");
        for (BeilvVoucherMember var : voucherMemberList) {
            var.setVoucherTypeText(MapUtils.getString(voucherType, var.getVoucherType()));
            var.setIsValidityText(MapUtils.getString(isValidity, var.getIsValidity()));
        }
        return voucherMemberList;
    }
}
