using System.Text.Json.Nodes; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Csob.Models; using Csob.Services; namespace Csob.Controllers; /// PISP – standing-order initiation and its authorization (sign) flow. Requires the ČSOB credential headers. [ApiController] [Route("standing-orders")] [Produces("application/json")] [Tags("PISP – Standing orders")] public sealed class StandingOrdersController : ControllerBase { private readonly StandingOrdersService _service; public StandingOrdersController(StandingOrdersService service) => _service = service; /// Initiate a standing order. [HttpPost] public async Task Initiate([FromBody] StandingOrderInitiationRequest request, CancellationToken ct) => Ok(await _service.InitiateAsync(request, ct)); /// Get the standing-order detail. [HttpGet("{id}")] public async Task Detail(string id, CancellationToken ct) => Ok(await _service.DetailAsync(id, ct)); /// Get the standing-order instruction status. [HttpGet("{id}/status")] public async Task Status(string id, CancellationToken ct) => Ok(await _service.StatusAsync(id, ct)); /// Cancel a standing order. [HttpDelete("{id}")] public async Task Cancel(string id, CancellationToken ct) => Ok(await _service.CancelAsync(id, ct)); /// Start the authorization (SCA) of a standing order. Returns the PSU redirect details. [HttpPost("{id}/sign/{signId}")] public async Task StartSign(string id, string signId, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] JsonNode? body, CancellationToken ct) => Ok(await _service.StartSignAsync(id, signId, body, ct)); /// Get the current state of an authorization (sign) transaction. [HttpGet("{id}/sign/{signId}")] public async Task SignStatus(string id, string signId, CancellationToken ct) => Ok(await _service.SignStatusAsync(id, signId, ct)); /// Finalize an authorization (sign) transaction. [HttpPut("{id}/sign/{signId}")] public async Task FinalizeSign(string id, string signId, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] JsonNode? body, CancellationToken ct) => Ok(await _service.FinalizeSignAsync(id, signId, body, ct)); }