package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopUserCouponMapper;
import com.gxwebsoft.shop.service.ShopUserCouponService;
import com.gxwebsoft.shop.entity.ShopUserCoupon;
import com.gxwebsoft.shop.param.ShopUserCouponParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户优惠券Service实现
 *
 * @author 科技小王子
 * @since 2025-08-11 23:51:41
 */
@Service
public class ShopUserCouponServiceImpl extends ServiceImpl<ShopUserCouponMapper, ShopUserCoupon> implements ShopUserCouponService {

    @Override
    public PageResult<ShopUserCoupon> pageRel(ShopUserCouponParam param) {
        PageParam<ShopUserCoupon, ShopUserCouponParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        List<ShopUserCoupon> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<ShopUserCoupon> listRel(ShopUserCouponParam param) {
        List<ShopUserCoupon> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<ShopUserCoupon, ShopUserCouponParam> page = new PageParam<>();
        page.setDefaultOrder("sort_number asc, create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public ShopUserCoupon getByIdRel(Integer id) {
        ShopUserCouponParam param = new ShopUserCouponParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }


    @Override
    public List<ShopUserCoupon> userList(Integer userId) {
        return list(
                new LambdaQueryWrapper<ShopUserCoupon>()
                        .eq(ShopUserCoupon::getUserId, userId)
        );
    }

}
