package com.yushu.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.yushu.common.annotation.Log;
import com.yushu.common.core.controller.BaseController;
import com.yushu.common.core.domain.AjaxResult;
import com.yushu.common.core.page.TableDataInfo;
import com.yushu.common.enums.BusinessType;
import com.yushu.common.utils.poi.ExcelUtil;
import com.yushu.system.domain.AiProvider;
import com.yushu.system.service.IAiProviderService;

/**
 * AI厂商Controller
 * 
 * @author yushu
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/system/ai/provider")
public class AiProviderController extends BaseController {
    
    @Autowired
    private IAiProviderService aiProviderService;

    /**
     * 查询AI厂商列表
     */
    @PreAuthorize("@ss.hasPermi('ai:provider:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiProvider aiProvider) {
        startPage();
        List<AiProvider> list = aiProviderService.selectAiProviderList(aiProvider);
        return getDataTable(list);
    }

    /**
     * 导出AI厂商列表
     */
    @PreAuthorize("@ss.hasPermi('ai:provider:export')")
    @Log(title = "AI厂商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiProvider aiProvider) {
        List<AiProvider> list = aiProviderService.selectAiProviderList(aiProvider);
        ExcelUtil<AiProvider> util = new ExcelUtil<>(AiProvider.class);
        util.exportExcel(response, list, "AI厂商数据");
    }

    /**
     * 获取AI厂商详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:provider:query')")
    @GetMapping(value = "/{providerId}")
    public AjaxResult getInfo(@PathVariable("providerId") Long providerId) {
        return success(aiProviderService.selectAiProviderByProviderId(providerId));
    }

    /**
     * 新增AI厂商
     */
    @PreAuthorize("@ss.hasPermi('ai:provider:add')")
    @Log(title = "AI厂商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiProvider aiProvider) {
        return toAjax(aiProviderService.insertAiProvider(aiProvider));
    }

    /**
     * 修改AI厂商
     */
    @PreAuthorize("@ss.hasPermi('ai:provider:edit')")
    @Log(title = "AI厂商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiProvider aiProvider) {
        return toAjax(aiProviderService.updateAiProvider(aiProvider));
    }

    /**
     * 删除AI厂商
     */
    @PreAuthorize("@ss.hasPermi('ai:provider:remove')")
    @Log(title = "AI厂商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{providerIds}")
    public AjaxResult remove(@PathVariable Long[] providerIds) {
        return toAjax(aiProviderService.deleteAiProviderByProviderIds(providerIds));
    }
}

