using Heimdall.Application.Common;
using Heimdall.Application.DTOs;
namespace Heimdall.Application.Services;
///
/// Camera discovery service — probes network devices, searches the camera
/// database, builds and tests stream URLs, and creates Camera entities.
/// Inspired by Strix (github.com/eduard256/Strix).
///
public interface ICameraDiscoveryService
{
///
/// Probe a single IP address using all available methods in parallel
/// (ONVIF WS-Discovery, HTTP, mDNS, ARP, port scan). Returns within ~100ms.
///
Task> ProbeIpAsync(
ProbeRequest request, CancellationToken ct);
///
/// Scan an entire subnet for camera devices. Runs port scans in parallel
/// with 20+ workers. Reports progress via IProgress{ScanProgress}.
///
Task>> ScanSubnetAsync(
ScanRequest request, CancellationToken ct,
IProgress? progress = null);
///
/// Search the built-in camera database (StrixCamDB) by brand, model, or preset.
/// Supports multi-word queries (each word matches independently).
///
Task> SearchDatabaseAsync(
string query, CancellationToken ct);
///
/// Build full stream URLs from camera database entries, substituting
/// placeholders ([CHANNEL], [USERNAME], [IP], etc.) with actual values.
///
Task> BuildStreamUrlsAsync(
StreamBuildRequest request, CancellationToken ct);
///
/// Test stream URLs in parallel (20 workers) — connects to each,
/// extracts codecs, resolution, latency, and captures a screenshot.
/// Returns a session ID for polling.
///
Task> TestStreamsAsync(
StreamTestRequest request, CancellationToken ct);
///
/// Poll a stream test session for updated results.
///
Task> GetTestSessionAsync(
Guid sessionId, CancellationToken ct);
///
/// Get a screenshot from a stream test session.
///
Task GetScreenshotAsync(
Guid sessionId, int index, CancellationToken ct);
///
/// Cancel a running stream test session.
///
Task CancelTestSessionAsync(
Guid sessionId, CancellationToken ct);
///
/// Confirm a discovery result — creates a Camera entity with all
/// discovered metadata, credentials (encrypted), and an optional
/// detection profile.
///
Task> ConfirmDiscoveryAsync(
ConfirmDiscoveryRequest request, CancellationToken ct);
///
/// Check if a camera with the same IP or MAC already exists for this site.
/// Use this before ConfirmDiscoveryAsync to avoid duplicate cameras.
///
Task> CheckDuplicateAsync(
CheckDuplicateRequest request, CancellationToken ct);
///
/// Receive a batch of devices probed by an agent's network scan. Persists
/// them as CameraDiscoveryResult (upsert by site+IP for unprocessed results),
/// then enriches each candidate: authenticated ONVIF GetDeviceInformation
/// using the site's declared credential pool, and candidate stream URL
/// building from the built-in camera database.
///
Task> SubmitAgentDiscoveriesAsync(
Guid agentId, IReadOnlyList devices, CancellationToken ct);
///
/// List pending (unprocessed) discovery results for a site, newest first.
///
Task>> ListPendingDiscoveriesAsync(
Guid siteId, CancellationToken ct);
///
/// Mark a discovery result as rejected (ignored) so it no longer appears
/// in the pending list. Does not delete the row.
///
Task RejectDiscoveryAsync(Guid resultId, CancellationToken ct);
///
/// Get the in-memory screenshot (agent-captured JPEG) for a discovery
/// result. Returns null when absent or expired (TTL 10 min).
///
byte[]? GetDiscoveryScreenshot(Guid resultId);
}