package com.qqchen.deploy.backend.workflow.service.impl;

import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import com.qqchen.deploy.backend.workflow.dto.FormCategoryDTO;
import com.qqchen.deploy.backend.workflow.dto.query.FormCategoryQuery;
import com.qqchen.deploy.backend.workflow.entity.FormCategory;
import com.qqchen.deploy.backend.workflow.repository.IFormCategoryRepository;
import com.qqchen.deploy.backend.workflow.service.IFormCategoryService;
import com.qqchen.deploy.backend.workflow.converter.FormCategoryConverter;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 表单分类服务实现
 *
 * @author qqchen
 * @date 2025-10-24
 */
@Slf4j
@Service
public class FormCategoryServiceImpl extends BaseServiceImpl<FormCategory, FormCategoryDTO, FormCategoryQuery, Long> implements IFormCategoryService {

    @Resource
    private IFormCategoryRepository formCategoryRepository;

    @Resource
    private FormCategoryConverter formCategoryConverter;

    @Override
    public List<FormCategoryDTO> findAllEnabled() {
        log.info("查询所有启用的表单分类");
        List<FormCategory> categories = formCategoryRepository.findByEnabledTrueAndDeletedFalseOrderBySortAsc();
        return categories.stream()
                .map(formCategoryConverter::toDto)
                .collect(Collectors.toList());
    }
}

