package com.mall.member.service.impl;

import com.mall.member.mapper.MemberReceiveAddressMapper;
import com.mall.member.service.MemberReceiveAddressService;
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.MemberReceiveAddressService;
import com.mall.member.domain.dto.MemberReceiveAddressDto;
import com.mall.member.domain.entity.MemberReceiveAddress;
import com.mall.member.domain.vo.MemberReceiveAddressVo;
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 MemberReceiveAddressServiceImpl extends ServiceImpl<MemberReceiveAddressMapper, MemberReceiveAddress> implements MemberReceiveAddressService {

    /**
     * * 会员收货地址 服务实现类
     *
     * @param pageParams 会员收货地址分页查询page对象
     * @param dto        会员收货地址分页查询对象
     * @return 查询分页会员收货地址返回对象
     */
    @Override
    public PageResult<MemberReceiveAddressVo> getMemberReceiveAddressPage(Page<MemberReceiveAddress> pageParams, MemberReceiveAddressDto dto) {
        IPage<MemberReceiveAddressVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加会员收货地址
     *
     * @param dto 会员收货地址添加
     */
    @Override
    public void addMemberReceiveAddress(MemberReceiveAddressDto dto) {
        MemberReceiveAddress memberReceiveAddress =new MemberReceiveAddress();
        BeanUtils.copyProperties(dto, memberReceiveAddress);
        save(memberReceiveAddress);
    }

    /**
     * 更新会员收货地址
     *
     * @param dto 会员收货地址更新
     */
    @Override
    public void updateMemberReceiveAddress(MemberReceiveAddressDto dto) {
        MemberReceiveAddress memberReceiveAddress =new MemberReceiveAddress();
        BeanUtils.copyProperties(dto, memberReceiveAddress);
        updateById(memberReceiveAddress);
    }

    /**
     * 删除|批量删除会员收货地址
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteMemberReceiveAddress(List<Long> ids) {
        removeByIds(ids);
    }
}