package com.jeesharp.business.modules.ai.application;

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.ai.convert.AiFaqCategoryConvert;
import com.jeesharp.business.modules.ai.dto.AiFaqCategorySaveDTO;
import com.jeesharp.business.modules.ai.entity.AiFaqCategory;
import com.jeesharp.business.modules.ai.service.AiFaqCategoryService;
import com.jeesharp.business.modules.ai.vo.AiFaqCategoryInfoVO;
import com.jeesharp.business.modules.ai.vo.AiFaqCategoryListVO;
import com.jeesharp.business.modules.ai.vo.AiFaqCategoryQueryVO;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class AiFaqCategoryApplicationService {

    private final AiFaqCategoryService aiFaqCategoryService;

    public AiFaqCategoryInfoVO get(String id) {
        return AiFaqCategoryConvert.INSTANCE.toInfoVO(aiFaqCategoryService.get(id));
    }

    public PageRespVO<AiFaqCategoryListVO> findPage(Page<AiFaqCategory> page, AiFaqCategoryQueryVO query) {
        Page<AiFaqCategory> result = aiFaqCategoryService.findPage(page, query);
        return AiFaqCategoryConvert.INSTANCE.toPageRespVO(result);
    }

    @Transactional(readOnly = false)
    public void save(AiFaqCategorySaveDTO dto) {
        AiFaqCategory entity = AiFaqCategoryConvert.INSTANCE.toEntity(dto);
        if (StrUtil.isBlank(dto.getId())) {
            aiFaqCategoryService.createCategory(entity);
            return;
        }
        aiFaqCategoryService.updateCategory(entity);
    }

    @Transactional(readOnly = false)
    public void delete(String ids) {
        aiFaqCategoryService.batchDelete(StrUtil.splitTrim(ids, ','));
    }
}
