using System.Text.Json.Nodes;
using Csob.Client;

namespace Csob.Services;

/// <summary>
/// PISP – direct-debit mandate initiation, detail/status, revocation and the sign (SCA) flow.
/// The mandate creation body varies across COBS profiles, so it is accepted and forwarded as raw JSON.
/// </summary>
public sealed class DirectDebitsService
{
    private readonly CsobApiAccessor _accessor;

    public DirectDebitsService(CsobApiAccessor accessor) => _accessor = accessor;

    public Task<JsonNode?> InitiateAsync(JsonNode request, CancellationToken ct)
        => _accessor.Client.PostAsync(CsobApiPaths.DirectDebits, request, ct);

    public Task<JsonNode?> DetailAsync(string id, CancellationToken ct)
        => _accessor.Client.GetAsync(CsobApiPaths.DirectDebit(id), null, ct);

    public Task<JsonNode?> StatusAsync(string id, CancellationToken ct)
        => _accessor.Client.GetAsync(CsobApiPaths.DirectDebitStatus(id), null, ct);

    public Task<JsonNode?> CancelAsync(string id, CancellationToken ct)
        => _accessor.Client.DeleteAsync(CsobApiPaths.DirectDebit(id), ct);

    public Task<JsonNode?> StartSignAsync(string id, string signId, JsonNode? body, CancellationToken ct)
        => _accessor.Client.PostAsync(CsobApiPaths.DirectDebitSign(id, signId), body, ct);

    public Task<JsonNode?> SignStatusAsync(string id, string signId, CancellationToken ct)
        => _accessor.Client.GetAsync(CsobApiPaths.DirectDebitSign(id, signId), null, ct);

    public Task<JsonNode?> FinalizeSignAsync(string id, string signId, JsonNode? body, CancellationToken ct)
        => _accessor.Client.PutAsync(CsobApiPaths.DirectDebitSign(id, signId), body, ct);
}
