// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

namespace Gitea.SDK;

/// <summary>
/// Base exception for all Gitea SDK errors.
/// </summary>
public class GiteaException : Exception
{
    public GiteaException(string message) : base(message) { }
    public GiteaException(string message, Exception inner) : base(message, inner) { }
}

/// <summary>
/// Thrown when authentication fails (401).
/// </summary>
public class AuthenticationException : GiteaException
{
    public AuthenticationException(string message) : base(message) { }
}

/// <summary>
/// Thrown when a resource is not found (404).
/// </summary>
public class NotFoundException : GiteaException
{
    public NotFoundException(string message) : base(message) { }
}

/// <summary>
/// Thrown when the API returns an error response.
/// </summary>
public class ApiException : GiteaException
{
    public string? Code { get; }
    public int StatusCode { get; }

    public ApiException(string message, string? code, int statusCode)
        : base(message)
    {
        Code = code;
        StatusCode = statusCode;
    }
}

/// <summary>
/// Thrown when an upload operation fails.
/// </summary>
public class UploadException : GiteaException
{
    public string? SessionId { get; }
    public int? ChunkNumber { get; }

    public UploadException(string message, string? sessionId = null, int? chunkNumber = null)
        : base(message)
    {
        SessionId = sessionId;
        ChunkNumber = chunkNumber;
    }

    public UploadException(string message, Exception inner, string? sessionId = null, int? chunkNumber = null)
        : base(message, inner)
    {
        SessionId = sessionId;
        ChunkNumber = chunkNumber;
    }
}

/// <summary>
/// Thrown when checksum verification fails.
/// </summary>
public class ChecksumException : UploadException
{
    public string? Expected { get; }
    public string? Actual { get; }

    public ChecksumException(string message, string? expected = null, string? actual = null, string? sessionId = null)
        : base(message, sessionId)
    {
        Expected = expected;
        Actual = actual;
    }
}
