using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp;
using OpenAuth.App.ServiceApp.Algo;
using OpenAuth.App.ServiceApp.Algo.Request;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers.ServiceControllers;

/// <summary>
/// 算法实例
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class AlgoInstanceController : ControllerBase
{
    private readonly AlgoInstanceServiceApp _app;

    public AlgoInstanceController(AlgoInstanceServiceApp app)
    {
        _app = app;
    }

 
    /// <summary>
    /// 添加算法实例
    /// </summary>
    /// <param name="info"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> AddAlgoInstance(LasaAlgoInstance info)
    {
        return await _app.AddAlgoInstance(info);
    }

    /// <summary>
    /// 删除算法实例
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> DeleteAlgoInstance(string id)
    {
        return await _app.DeleteAlgoInstance(id);
    }

    /// <summary>
    /// 修改算法实例
    /// </summary>
    /// <param name="info"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> UpdateAlgoInstance(LasaAlgoInstance info)
    {
        return await _app.UpdateAlgoInstance(info);
    }

    /// <summary>
    /// 获取算法实例列表
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<IEnumerable<dynamic>>>> GetAlgoInstanceList(
        [FromQuery] AlgoInstancePageRequest req)
    {
        return await _app.GetAlgoInstanceList(req);
    }

    /// <summary>
    /// 获取算法实例详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<LasaAlgoInstance>> GetAlgoInstance(string id)
    {
        return await _app.GetAlgoInstance(id);
    }
}