namespace VideoDownloader.Server;
/// 다운로드 큐 항목 스냅shot (모바일/웹 컴패니언용).
public sealed record QueueItemDto(string Id, string Title, string Url, string Status, double Percent);
/// 라이브러리(저장 폴더) 미디어 항목.
public sealed record LibraryItemDto(string Id, string FileName, long SizeBytes, DateTime Modified);
/// 서버 구성.
public sealed class ServerOptions
{
/// 0 이면 사용 가능한 포트 자동 할당.
public int Port { get; init; }
/// 페어링 토큰(Bearer). 비면 자동 생성.
public string Token { get; init; } = "";
/// 라이브러리로 노출할 폴더.
public string LibraryFolder { get; init; } = "";
/// 다운로드 큐 어댑터(호스트 앱이 구현 주입).
public IQueueAdapter Queue { get; init; } = new EmptyQueueAdapter();
/// 기기 표시명(웹 컴패니언 헤더용).
public string DeviceName { get; init; } = Environment.MachineName;
}
/// 호스트 앱의 다운로드 큐와 서버를 잇는 어댑터(UI 스레드 마샬링은 구현측 담당).
public interface IQueueAdapter
{
Task> GetItemsAsync();
Task AddAsync(string url, string? title);
Task PauseAsync(string id);
Task ResumeAsync(string id);
Task CancelAsync(string id);
event Action? Changed;
}
/// 큐 없이 서버만 띄울 때의 기본 구현.
public sealed class EmptyQueueAdapter : IQueueAdapter
{
public Task> GetItemsAsync() =>
Task.FromResult>(Array.Empty());
public Task AddAsync(string url, string? title) => Task.FromResult("");
public Task PauseAsync(string id) => Task.CompletedTask;
public Task ResumeAsync(string id) => Task.CompletedTask;
public Task CancelAsync(string id) => Task.CompletedTask;
public event Action? Changed { add { } remove { } }
}