package org.eco.als.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.eco.als.domain.bo.KGraphClauseBo;
import org.eco.als.domain.vo.KGraphClauseVo;
import org.eco.als.service.IKGraphClauseService;
import org.eco.common.core.core.domain.CommonResult;
import org.eco.common.core.core.page.PageResult;
import org.eco.common.log.annotation.Log;
import org.eco.common.log.enums.BusinessType;
import org.eco.common.web.annotation.RepeatSubmit;
import org.eco.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 知识图谱分句结果Controller
 *
 * @author wgk
 * @date 2025-01-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/kGraphClause")
public class KGraphClauseController extends BaseController {
    @Resource
    private IKGraphClauseService kGraphClauseService;

    /**
     * 查询知识图谱分句结果列表
     */
    @SaCheckPermission("als:kGraphClause:list")
    @GetMapping("/list")
    public CommonResult<PageResult<KGraphClauseVo>> list(KGraphClauseBo kGraphClauseBo) {
        return CommonResult.success(kGraphClauseService.selectPage(kGraphClauseBo));
    }

    /**
     * 获取知识图谱分句结果详细信息
     */
    @SaCheckPermission("als:kGraphClause:query")
    @GetMapping(value = "/{id}")
    public CommonResult<KGraphClauseVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(kGraphClauseService.selectById(id));
    }

    /**
     * 新增知识图谱分句结果
     */
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody KGraphClauseBo kGraphClauseBo) {
        boolean inserted = kGraphClauseService.insert(kGraphClauseBo);
        if (!inserted) {
            return CommonResult.fail("新增知识图谱分句结果记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 新增知识图谱分句结果
     */
    @RepeatSubmit()
    @PostMapping("/saveBatch")
    public CommonResult<Void> saveBatch(@Valid @RequestBody List<KGraphClauseBo> kGraphClauseBoList) {
        boolean inserted = kGraphClauseService.saveBatch(kGraphClauseBoList);
        if (!inserted) {
            return CommonResult.fail("新增知识图谱分句结果记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改知识图谱分句结果
     */
    @SaCheckPermission("als:kGraphClause:edit")
    @Log(title = "知识图谱分句结果", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody KGraphClauseBo kGraphClauseBo) {
        boolean updated = kGraphClauseService.update(kGraphClauseBo);
        if (!updated) {
            return CommonResult.fail("修改知识图谱分句结果记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除知识图谱分句结果
     */
    @SaCheckPermission("als:kGraphClause:remove")
    @Log(title = "知识图谱分句结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = kGraphClauseService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除知识图谱分句结果记录失败!");
        }
        return CommonResult.success();
    }
}
