using Extrudex.Domain.DTOs.Moonraker;
namespace Extrudex.Domain.Interfaces;
///
/// Client interface for communicating with Moonraker REST API endpoints
/// on Klipper-based printers (e.g., Elegoo Centauri Carbon).
/// Provides strongly-typed methods for server discovery, printer status,
/// print job history, and real-time telemetry.
///
public interface IMoonrakerClient
{
///
/// Checks whether the Moonraker server is reachable and responding.
/// Calls the /server/info endpoint and returns the server information
/// if successful, or null if the server is unreachable.
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Cancellation token for the HTTP request.
/// Server info if reachable; null if unreachable.
Task GetServerInfoAsync(
string hostnameOrIp,
int port,
string? apiKey,
CancellationToken cancellationToken = default);
///
/// Checks whether the Moonraker server is reachable and responding.
/// This is a convenience method equivalent to calling GetServerInfoAsync
/// and checking for a non-null result.
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Cancellation token for the HTTP request.
/// true if the server responded successfully; otherwise false.
Task IsReachableAsync(
string hostnameOrIp,
int port,
string? apiKey,
CancellationToken cancellationToken = default);
///
/// Fetches the current printer info from the /printer/info endpoint.
/// Returns the Klipper state and readiness status.
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Cancellation token for the HTTP request.
/// Printer info if successful; null if the request failed.
Task GetPrinterInfoAsync(
string hostnameOrIp,
int port,
string? apiKey,
CancellationToken cancellationToken = default);
///
/// Fetches print job history from the /server/history/items endpoint.
/// Returns the most recent print jobs with filament usage data,
/// print duration, and completion status.
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Maximum number of history items to return. Default: 50.
/// Cancellation token for the HTTP request.
/// History response with print jobs; empty list if request failed.
Task GetPrintHistoryAsync(
string hostnameOrIp,
int port,
string? apiKey,
int limit = 50,
CancellationToken cancellationToken = default);
///
/// Fetches the current print statistics from the /printer/objects/query endpoint.
/// Returns real-time data including filament used, print duration,
/// and current print state for the active or most recent print.
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Cancellation token for the HTTP request.
/// Print stats if successful; null if the request failed.
Task GetPrintStatsAsync(
string hostnameOrIp,
int port,
string? apiKey,
CancellationToken cancellationToken = default);
///
/// Fetches the current display status from the /printer/objects/query endpoint.
/// Returns progress percentage and status message for the active print.
/// Used by SignalR to push real-time progress updates to connected clients.
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Cancellation token for the HTTP request.
/// Display status if successful; null if the request failed.
Task GetDisplayStatusAsync(
string hostnameOrIp,
int port,
string? apiKey,
CancellationToken cancellationToken = default);
///
/// Fetches the current filament usage data from the Moonraker server.
/// Returns a dictionary of usage metrics reported by the printer.
///
///
/// Prefer GetPrintHistoryAsync or GetPrintStatsAsync for new code.
/// This method is retained for backward compatibility with the
/// FilamentUsageSyncService and returns a dictionary of metric names
/// to their decimal values for callers that don't need typed DTOs.
///
///
/// The printer's hostname or IP address.
/// The Moonraker API port (default: 7125).
/// Optional API key for authentication.
/// Cancellation token for the HTTP request.
/// A dictionary of usage metric names to their decimal values.
Task> GetFilamentUsageAsync(
string hostnameOrIp,
int port,
string? apiKey,
CancellationToken cancellationToken = default);
}