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

namespace DodoSSH.Client.Sync;

/// <summary>
/// The snippets in this vault, decrypted, with unpushed local changes laid over them.
/// </summary>
/// <remarks>
/// The sixth facade over the same generic repository. Nothing here is on the terminal's write path: a snippet
/// is read when the screen that lists them opens, and inserting one hands text to the renderer rather than
/// coming back through the vault.
/// </remarks>
public sealed class SnippetRepository(
    ItemStore items,
    OutboxStore outbox,
    VaultKeyring keyring,
    IActivityLogSink? activity = null)
{
    private readonly VaultItemRepository<SnippetSecret> snippets =
        new(SnippetKind.Instance, items, outbox, keyring, activity);

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

    /// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
    public Task<Guid> CreateAsync(
        Guid vaultId,
        SnippetSecret snippet,
        CancellationToken cancellationToken) =>
        snippets.CreateAsync(vaultId, snippet, cancellationToken);

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

    /// <inheritdoc cref="VaultItemRepository{TSecret}.MoveAsync" />
    /// <remarks>
    /// What sharing a snippet is, underneath. A snippet has no group, no tags and no key binding — see
    /// <see cref="SnippetSecret"/> — so unlike a host it crosses whole: nothing about it points at an item
    /// of the vault it is leaving, and there is consequently nothing to strip on the way across.
    /// </remarks>
    public Task<Guid> MoveAsync(
        Guid fromVaultId,
        Guid toVaultId,
        Guid entityId,
        SnippetSecret snippet,
        CancellationToken cancellationToken) =>
        snippets.MoveAsync(fromVaultId, toVaultId, entityId, snippet, cancellationToken);

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