using Nexus.Api.Models;

namespace Nexus.Api.Services;

public interface IOpenClawAgentConfigurationService
{
    Task<OpenClawAgentFileCollectionDto> GetAgentFilesAsync(
        string agentId,
        CancellationToken cancellationToken = default);

    Task<OpenClawAgentFileDto> GetAgentFileAsync(
        string agentId,
        string fileName,
        CancellationToken cancellationToken = default);

    Task<OpenClawAgentFileWriteDto> SetAgentFileAsync(
        string agentId,
        string fileName,
        UpdateOpenClawAgentFileRequest request,
        OpenClawInvocationContext invocationContext,
        CancellationToken cancellationToken = default);

    Task<OpenClawWorkspaceCollectionDto> GetWorkspaceAsync(
        string agentId,
        string? path,
        int offset,
        int limit,
        CancellationToken cancellationToken = default);

    Task<OpenClawWorkspaceFileDto> GetWorkspaceFileAsync(
        string agentId,
        string path,
        CancellationToken cancellationToken = default);

    Task<OpenClawConfigSchemaLookupDto> GetConfigSchemaAsync(
        string path,
        CancellationToken cancellationToken = default);

    Task<OpenClawConfigSnapshotDto> GetConfigAsync(
        CancellationToken cancellationToken = default);

    Task<OpenClawConfigPatchDto> PatchConfigAsync(
        PatchOpenClawConfigRequest request,
        OpenClawInvocationContext invocationContext,
        CancellationToken cancellationToken = default);
}

public sealed class OpenClawAgentConfigurationValidationException(
    string field,
    string message) : Exception(message)
{
    public string Field { get; } = field;
}

public sealed class OpenClawAgentConfigurationConflictException(
    string code,
    string message,
    string? expectedHash = null,
    string? currentHash = null) : Exception(message)
{
    public string Code { get; } = code;
    public string? ExpectedHash { get; } = expectedHash;
    public string? CurrentHash { get; } = currentHash;
}

public sealed class OpenClawAgentConfigurationUnavailableException(
    string state,
    string method,
    string requiredScope,
    string message) : Exception(message)
{
    public string State { get; } = state;
    public string Method { get; } = method;
    public string RequiredScope { get; } = requiredScope;
}

public sealed class OpenClawAgentConfigurationVerificationException(
    string message) : Exception(message);
