using Nexus.Api.Data;

namespace Nexus.Api.Repositories;

public interface IOpenClawConnectionProfileRepository
{
    Task<OpenClawConnectionProfile?> GetPrimaryAsync(
        CancellationToken cancellationToken = default);

    Task<OpenClawConnectionProfile> SavePrimaryAsync(
        OpenClawConnectionProfile profile,
        int? expectedRevision,
        CancellationToken cancellationToken = default);

    Task<bool> DeletePrimaryAsync(
        int expectedRevision,
        CancellationToken cancellationToken = default);
}

public sealed class OpenClawConnectionProfileConcurrencyException : Exception
{
    public OpenClawConnectionProfileConcurrencyException(
        string message,
        int? currentRevision = null)
        : base(message)
    {
        CurrentRevision = currentRevision;
    }

    public OpenClawConnectionProfileConcurrencyException(
        string message,
        Exception innerException)
        : base(message, innerException)
    {
    }

    public int? CurrentRevision { get; }
}
