package com.ruoyi.aicall.controller;

import java.util.List;

import com.ruoyi.aicall.domain.CcAsrLanguages;
import com.ruoyi.aicall.service.ICcAsrLanguagesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ASR语种及模型配置Controller
 * 
 * @author ruoyi
 * @date 2026-04-08
 */
@Controller
@RequestMapping("/system/languages")
public class CcAsrLanguagesController extends BaseController
{
    private String prefix = "system/languages";

    @Autowired
    private ICcAsrLanguagesService ccAsrLanguagesService;

    @RequiresPermissions("system:languages:view")
    @GetMapping()
    public String languages()
    {
        return prefix + "/languages";
    }

    /**
     * 查询ASR语种及模型配置列表
     */
    @RequiresPermissions("system:languages:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CcAsrLanguages ccAsrLanguages)
    {
        startPage();
        List<CcAsrLanguages> list = ccAsrLanguagesService.selectCcAsrLanguagesList(ccAsrLanguages);
        return getDataTable(list);
    }

    /**
     * 导出ASR语种及模型配置列表
     */
    @RequiresPermissions("system:languages:export")
    @Log(title = "ASR语种及模型配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CcAsrLanguages ccAsrLanguages)
    {
        List<CcAsrLanguages> list = ccAsrLanguagesService.selectCcAsrLanguagesList(ccAsrLanguages);
        ExcelUtil<CcAsrLanguages> util = new ExcelUtil<CcAsrLanguages>(CcAsrLanguages.class);
        return util.exportExcel(list, "ASR语种及模型配置数据");
    }

    /**
     * 新增ASR语种及模型配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存ASR语种及模型配置
     */
    @RequiresPermissions("system:languages:add")
    @Log(title = "ASR语种及模型配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CcAsrLanguages ccAsrLanguages)
    {
        return toAjax(ccAsrLanguagesService.insertCcAsrLanguages(ccAsrLanguages));
    }

    /**
     * 修改ASR语种及模型配置
     */
    @RequiresPermissions("system:languages:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CcAsrLanguages ccAsrLanguages = ccAsrLanguagesService.selectCcAsrLanguagesById(id);
        mmap.put("ccAsrLanguages", ccAsrLanguages);
        return prefix + "/edit";
    }

    /**
     * 修改保存ASR语种及模型配置
     */
    @RequiresPermissions("system:languages:edit")
    @Log(title = "ASR语种及模型配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CcAsrLanguages ccAsrLanguages)
    {
        return toAjax(ccAsrLanguagesService.updateCcAsrLanguages(ccAsrLanguages));
    }

    /**
     * 删除ASR语种及模型配置
     */
    @RequiresPermissions("system:languages:remove")
    @Log(title = "ASR语种及模型配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ccAsrLanguagesService.deleteCcAsrLanguagesByIds(ids));
    }
}
