using Books.Api.Domain.BankConnections;
using Books.Api.Domain.BankConnections.Events;
using EventFlow.Commands;

namespace Books.Api.Commands.BankConnections;

public class InitiateBankConnectionCommand(
    BankConnectionId aggregateId,
    string companyId,
    string aspspName,
    string authorizationId,
    string redirectUrl,
    string state)
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string CompanyId { get; } = companyId;
    public string AspspName { get; } = aspspName;
    public string AuthorizationId { get; } = authorizationId;
    public string RedirectUrl { get; } = redirectUrl;
    public string State { get; } = state;
}

public class EstablishBankConnectionCommand(
    BankConnectionId aggregateId,
    string sessionId,
    DateTimeOffset validUntil,
    IReadOnlyList<BankAccountInfo> accounts)
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string SessionId { get; } = sessionId;
    public DateTimeOffset ValidUntil { get; } = validUntil;
    public IReadOnlyList<BankAccountInfo> Accounts { get; } = accounts;
}

public class FailBankConnectionCommand(
    BankConnectionId aggregateId,
    string reason)
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string Reason { get; } = reason;
}

public class DisconnectBankConnectionCommand(
    BankConnectionId aggregateId,
    string reason = "User requested disconnection")
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string Reason { get; } = reason;
}

public class RefreshBankConnectionCommand(
    BankConnectionId aggregateId,
    string newSessionId,
    DateTimeOffset validUntil)
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string NewSessionId { get; } = newSessionId;
    public DateTimeOffset ValidUntil { get; } = validUntil;
}

public class LinkBankAccountCommand(
    BankConnectionId aggregateId,
    string bankAccountId,
    string linkedAccountId,
    DateOnly? importFromDate = null)
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string BankAccountId { get; } = bankAccountId;
    public string LinkedAccountId { get; } = linkedAccountId;
    public DateOnly? ImportFromDate { get; } = importFromDate;
}

public class ReInitiateBankConnectionCommand(
    BankConnectionId aggregateId,
    string authorizationId,
    string redirectUrl,
    string state)
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string AuthorizationId { get; } = authorizationId;
    public string RedirectUrl { get; } = redirectUrl;
    public string State { get; } = state;
}

public class ArchiveBankConnectionCommand(
    BankConnectionId aggregateId,
    string reason = "User requested archival")
    : Command<BankConnectionAggregate, BankConnectionId>(aggregateId)
{
    public string Reason { get; } = reason;
}
