using DodoSSH.Client.Domain;
using DodoSSH.Client.Storage;

namespace DodoSSH.Client.Sync;

/// <summary>
/// The hosts in a vault, decrypted, with unpushed local changes laid over them.
/// </summary>
/// <remarks>
/// A named facade over <see cref="VaultItemRepository{TSecret}"/>, which holds the logic and is shared
/// with <see cref="SshKeyRepository"/>. Two reasons it is a facade rather than the generic class itself:
/// callers read better for having asked for hosts by name, and the item kind that parameterises the
/// generic is internal to this assembly — exposing it would make the encoding and merge of every item
/// type part of the public surface for the sake of a constructor argument.
/// </remarks>
public sealed class HostRepository(
    ItemStore items,
    OutboxStore outbox,
    VaultKeyring keyring,
    IActivityLogSink? activity = null)
{
    private readonly VaultItemRepository<HostSecret> hosts =
        new(HostKind.Instance, items, outbox, keyring, activity);

    /// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
    public Task<ItemListing<HostSecret>> ListAsync(Guid vaultId, CancellationToken cancellationToken) =>
        hosts.ListAsync(vaultId, cancellationToken);

    /// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
    public Task<Guid> CreateAsync(Guid vaultId, HostSecret host, CancellationToken cancellationToken) =>
        hosts.CreateAsync(vaultId, host, cancellationToken);

    /// <inheritdoc cref="VaultItemRepository{TSecret}.UpdateAsync" />
    public Task UpdateAsync(
        Guid vaultId,
        Guid entityId,
        HostSecret host,
        CancellationToken cancellationToken) =>
        hosts.UpdateAsync(vaultId, entityId, host, cancellationToken);

    /// <inheritdoc cref="VaultItemRepository{TSecret}.MoveAsync" />
    public Task<Guid> MoveAsync(
        Guid fromVaultId,
        Guid toVaultId,
        Guid entityId,
        HostSecret host,
        CancellationToken cancellationToken) =>
        hosts.MoveAsync(fromVaultId, toVaultId, entityId, host, cancellationToken);

    /// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
    public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
        hosts.DeleteAsync(vaultId, entityId, cancellationToken);
}
