package com.bizzan.bitrade.service;

import com.bizzan.bitrade.dao.SysHelpCategoryDao;
import com.bizzan.bitrade.entity.SysHelpCategory;
import com.bizzan.bitrade.service.Base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SysHelpCategoryService extends BaseService {

    @Autowired
    private SysHelpCategoryDao dao;

    public SysHelpCategory save(SysHelpCategory category) {
        return dao.save(category);
    }

    public SysHelpCategory findOne(Long id) {
        return dao.findOne(id);
    }

    public SysHelpCategory findByCode(String code) {
        return dao.findByCode(code);
    }

    /** 所有启用的分类（按 sort 倒序） */
    public List<SysHelpCategory> findEnabled() {
        return dao.findByStatusOrderBySortDesc(1);
    }

    /** 按场景筛选启用的分类 */
    public List<SysHelpCategory> findEnabledByScene(String scene) {
        return dao.findByStatusAndSceneOrderBySortDesc(1, scene);
    }

    @Override
    public List<SysHelpCategory> findAll() {
        return dao.findAll();
    }

    public Page<SysHelpCategory> findAll(Pageable pageable) {
        return dao.findAll(pageable);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            dao.delete(id);
        }
    }
}
