using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace Csob.Models;

public sealed class StandingOrderIdentification
{
    public string? InstructionIdentification { get; set; }
    public string? TransactionIdentification { get; set; }
}

public sealed class StandingOrderExecution
{
    /// <summary>DAILY, WEEKLY, MONTHLY, BI_MONTHLY, QUARTERLY, HALFYEARLY, YEARLY, SINGLE, IRREGULAR.</summary>
    public string? Interval { get; set; }
    /// <summary>Day within the interval (e.g. day-of-month "25").</summary>
    public string? IntervalDue { get; set; }
    /// <summary>e.g. MAX_AMOUNT_EXCEEDED, UNTIL_CANCELLATION.</summary>
    public string? Mode { get; set; }
    public string? ModeDue { get; set; }
}

public sealed class StandingOrderDetail
{
    public string? Alias { get; set; }
    public StandingOrderExecution? Execution { get; set; }
    /// <summary>Optional <c>exceptions</c> block (stoppages/breaks); shape varies, kept as raw JSON.</summary>
    public JsonNode? Exceptions { get; set; }
    /// <summary>Optional <c>validity</c> block (lastExecutionDate/maxAmount); kept as raw JSON.</summary>
    public JsonNode? Validity { get; set; }
}

/// <summary>Standing-order initiation request (<c>POST /my/standingorders</c>).</summary>
public sealed class StandingOrderInitiationRequest
{
    public StandingOrderIdentification? StandingOrderIdentification { get; set; }
    public PaymentTypeInformation? PaymentTypeInformation { get; set; }
    public AmountContainer Amount { get; set; } = new();
    public string? RequestedExecutionDate { get; set; }
    public StandingOrderDetail? StandingOrder { get; set; }
    public AccountReference DebtorAccount { get; set; } = new();
    public AccountReference CreditorAccount { get; set; } = new();
    public RemittanceInformation? RemittanceInformation { get; set; }

    [JsonExtensionData]
    public Dictionary<string, JsonElement>? AdditionalData { get; set; }
}
