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

namespace Csob.Services;

/// <summary>PISP – standing-order initiation, detail/status, cancellation and the sign (SCA) flow.</summary>
public sealed class StandingOrdersService
{
    private readonly CsobApiAccessor _accessor;

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

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

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

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

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

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

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

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