package org.dromara.pet.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pet.domain.vo.BizTriageSessionsVo;
import org.dromara.pet.domain.bo.BizTriageSessionsBo;
import org.dromara.pet.service.IBizTriageSessionsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * AI智能分诊会话
 *
 * @author shuo
 * @date 2026-02-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pet/triageSessions")
public class BizTriageSessionsController extends BaseController {

    private final IBizTriageSessionsService bizTriageSessionsService;

/**
 * 查询AI智能分诊会话列表
 */
@SaCheckPermission("pet:triageSessions:list")
@GetMapping("/list")
    public TableDataInfo<BizTriageSessionsVo> list(BizTriageSessionsBo bo, PageQuery pageQuery) {
        return bizTriageSessionsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出AI智能分诊会话列表
     */
    @SaCheckPermission("pet:triageSessions:export")
    @Log(title = "AI智能分诊会话", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BizTriageSessionsBo bo, HttpServletResponse response) {
        List<BizTriageSessionsVo> list = bizTriageSessionsService.queryList(bo);
        ExcelUtil.exportExcel(list, "AI智能分诊会话", BizTriageSessionsVo.class, response);
    }

    /**
     * 获取AI智能分诊会话详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pet:triageSessions:query")
    @GetMapping("/{id}")
    public R<BizTriageSessionsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(bizTriageSessionsService.queryById(id));
    }

    /**
     * 新增AI智能分诊会话
     */
    @SaCheckPermission("pet:triageSessions:add")
    @Log(title = "AI智能分诊会话", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BizTriageSessionsBo bo) {
        return toAjax(bizTriageSessionsService.insertByBo(bo));
    }

    /**
     * 修改AI智能分诊会话
     */
    @SaCheckPermission("pet:triageSessions:edit")
    @Log(title = "AI智能分诊会话", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BizTriageSessionsBo bo) {
        return toAjax(bizTriageSessionsService.updateByBo(bo));
    }

    /**
     * 删除AI智能分诊会话
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pet:triageSessions:remove")
    @Log(title = "AI智能分诊会话", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(bizTriageSessionsService.deleteWithValidByIds(List.of(ids), true));
    }
}
