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.ShopCouponApplyItemMapper;
import com.gxwebsoft.shop.service.ShopCouponApplyItemService;
import com.gxwebsoft.shop.entity.ShopCouponApplyItem;
import com.gxwebsoft.shop.param.ShopCouponApplyItemParam;
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 12:47:49
 */
@Service
public class ShopCouponApplyItemServiceImpl extends ServiceImpl<ShopCouponApplyItemMapper, ShopCouponApplyItem> implements ShopCouponApplyItemService {

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

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

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

    @Override
    public void removeByCouponId(Integer couponId) {
        remove(
                new LambdaQueryWrapper<ShopCouponApplyItem>()
                        .eq(ShopCouponApplyItem::getCouponId, couponId)
        );
    }

}
