package com.mall.member.service.impl;

import com.mall.member.mapper.MemberLevelMapper;
import com.mall.member.service.MemberLevelService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mall.member.service.MemberLevelService;
import com.mall.member.domain.dto.MemberLevelDto;
import com.mall.member.domain.entity.MemberLevel;
import com.mall.member.domain.vo.MemberLevelVo;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 会员等级 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 19:30:06
 */
@Service
@Transactional
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelMapper, MemberLevel> implements MemberLevelService {

    /**
     * * 会员等级 服务实现类
     *
     * @param pageParams 会员等级分页查询page对象
     * @param dto        会员等级分页查询对象
     * @return 查询分页会员等级返回对象
     */
    @Override
    public PageResult<MemberLevelVo> getMemberLevelPage(Page<MemberLevel> pageParams, MemberLevelDto dto) {
        IPage<MemberLevelVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<MemberLevelVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加会员等级
     *
     * @param dto 会员等级添加
     */
    @Override
    public void addMemberLevel(MemberLevelDto dto) {
        MemberLevel memberLevel =new MemberLevel();
        BeanUtils.copyProperties(dto, memberLevel);
        save(memberLevel);
    }

    /**
     * 更新会员等级
     *
     * @param dto 会员等级更新
     */
    @Override
    public void updateMemberLevel(MemberLevelDto dto) {
        MemberLevel memberLevel =new MemberLevel();
        BeanUtils.copyProperties(dto, memberLevel);
        updateById(memberLevel);
    }

    /**
     * 删除|批量删除会员等级
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteMemberLevel(List<Long> ids) {
        removeByIds(ids);
    }
}