using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Mvc;
using Csob.Services;

namespace Csob.Controllers;

/// <summary>
/// Common – PSU consent lifecycle. Requires the ČSOB credential headers. The consent body is
/// forwarded to ČSOB as raw JSON (COBS consent shape).
/// </summary>
[ApiController]
[Route("consents")]
[Produces("application/json")]
[Tags("Consents")]
public sealed class ConsentsController : ControllerBase
{
    private readonly ConsentsService _service;

    public ConsentsController(ConsentsService service) => _service = service;

    /// <summary>Create a consent.</summary>
    [HttpPost]
    public async Task<IActionResult> Create([FromBody] JsonNode request, CancellationToken ct)
        => Ok(await _service.CreateAsync(request, ct));

    /// <summary>Get a consent detail.</summary>
    [HttpGet("{id}")]
    public async Task<IActionResult> Detail(string id, CancellationToken ct)
        => Ok(await _service.DetailAsync(id, ct));

    /// <summary>Revoke a consent.</summary>
    [HttpDelete("{id}")]
    public async Task<IActionResult> Delete(string id, CancellationToken ct)
        => Ok(await _service.DeleteAsync(id, ct));
}
