package com.fs.aiSipCall.controller;

import com.fs.aiSipCall.domain.AiSipCallGateway;
import com.fs.aiSipCall.service.IAiSipCallGatewayService;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * aiSIP外呼网关Controller
 * 
 * @author fs
 * @date 2026-03-06
 */
@RestController
@RequestMapping("/aiSipCall/gateway")
public class AiSipCallGatewayController extends BaseController
{
    @Autowired
    private IAiSipCallGatewayService aiSipCallGatewayService;

    /**
     * 查询aiSIP外呼网关列表
     */
    @PostMapping("/remoteList")
    public TableDataInfo remoteList(@RequestBody AiSipCallGateway aiSipCallGateway)
    {
        return aiSipCallGatewayService.remoteList(aiSipCallGateway);
    }
    /**
     * 查询aiSIP外呼网关列表
     */
    @PreAuthorize("@ss.hasPermi('aiSipCall:gateway:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiSipCallGateway aiSipCallGateway)
    {
        startPage();
        List<AiSipCallGateway> list = aiSipCallGatewayService.selectAiSipCallGatewayList(aiSipCallGateway);
        return getDataTable(list);
    }

    /**
     * 导出aiSIP外呼网关列表
     */
    @PreAuthorize("@ss.hasPermi('aiSipCall:gateway:export')")
    @Log(title = "aiSIP外呼网关", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AiSipCallGateway aiSipCallGateway)
    {
        List<AiSipCallGateway> list = aiSipCallGatewayService.selectAiSipCallGatewayList(aiSipCallGateway);
        ExcelUtil<AiSipCallGateway> util = new ExcelUtil<>(AiSipCallGateway.class);
        return util.exportExcel(list, "aiSIP外呼网关数据");
    }

    /**
     * 获取aiSIP外呼网关详细信息
     */
    @PreAuthorize("@ss.hasPermi('aiSipCall:gateway:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(aiSipCallGatewayService.selectAiSipCallGatewayById(id));
    }

    /**
     * 新增aiSIP外呼网关
     */
    @PreAuthorize("@ss.hasPermi('aiSipCall:gateway:add')")
    @Log(title = "aiSIP外呼网关", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiSipCallGateway aiSipCallGateway)
    {
        if(aiSipCallGateway.getUpdateTime() == null){
            aiSipCallGateway.setUpdateTime(new Date());
        }
        return toAjax(aiSipCallGatewayService.insertAiSipCallGateway(aiSipCallGateway));
    }

    /**
     * 修改aiSIP外呼网关
     */
    @PreAuthorize("@ss.hasPermi('aiSipCall:gateway:edit')")
    @Log(title = "aiSIP外呼网关", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiSipCallGateway aiSipCallGateway)
    {
        return toAjax(aiSipCallGatewayService.updateAiSipCallGateway(aiSipCallGateway));
    }

    /**
     * 删除aiSIP外呼网关
     */
    @PreAuthorize("@ss.hasPermi('aiSipCall:gateway:remove')")
    @Log(title = "aiSIP外呼网关", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiSipCallGatewayService.deleteAiSipCallGatewayByIds(ids));
    }
}
