using Microsoft.AspNetCore.Mvc;
using Meezi.Admin.API.Models;
using Meezi.Admin.API.Services;
using Meezi.Shared;

namespace Meezi.Admin.API.Controllers;

[Route("api/admin/integrations")]
public class AdminIntegrationsController : AdminApiControllerBase
{
    private readonly IPlatformIntegrationService _integrations;

    public AdminIntegrationsController(IPlatformIntegrationService integrations)
    {
        _integrations = integrations;
    }

    [HttpGet]
    public async Task<IActionResult> Get(CancellationToken cancellationToken)
    {
        var data = await _integrations.GetIntegrationsAsync(cancellationToken);
        return Ok(new ApiResponse<PlatformIntegrationsDto>(true, data));
    }

    [HttpPut]
    public async Task<IActionResult> Save(
        [FromBody] UpdatePlatformIntegrationsRequest request,
        CancellationToken cancellationToken)
    {
        await _integrations.SaveIntegrationsAsync(request, cancellationToken);
        var data = await _integrations.GetIntegrationsAsync(cancellationToken);
        return Ok(new ApiResponse<PlatformIntegrationsDto>(true, data));
    }
}
