package com.cms.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cms.entity.SysHelpCategory;
import com.cms.mapper.SysHelpCategoryMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysHelpCategoryService extends ServiceImpl<SysHelpCategoryMapper, SysHelpCategory> {

    /**
     * 查询所有启用的分类，按 sort 倒序
     */
    public List<SysHelpCategory> listEnabled() {
        return list(new LambdaQueryWrapper<SysHelpCategory>()
                .eq(SysHelpCategory::getStatus, 1)
                .orderByDesc(SysHelpCategory::getSort));
    }

    /**
     * 按场景查询启用的分类
     */
    public List<SysHelpCategory> listEnabledByScene(String scene) {
        return list(new LambdaQueryWrapper<SysHelpCategory>()
                .eq(SysHelpCategory::getStatus, 1)
                .eq(SysHelpCategory::getScene, scene)
                .orderByDesc(SysHelpCategory::getSort));
    }

    /**
     * 按 code 查询
     */
    public SysHelpCategory getByCode(String code) {
        return getOne(new LambdaQueryWrapper<SysHelpCategory>()
                .eq(SysHelpCategory::getCode, code)
                .last("limit 1"));
    }
}
