| 1 | using System.Security; |
| 2 | using Zipelo.Core; |
| 3 | |
| 4 | namespace Zipelo.Desktop; |
| 5 | |
| 6 | public enum WorkspaceAction |
| 7 | { |
| 8 | List, |
| 9 | Extract, |
| 10 | Create |
| 11 | } |
| 12 | |
| 13 | public enum WorkspaceOutcome |
| 14 | { |
| 15 | Completed, |
| 16 | Partial, |
| 17 | Cancelled, |
| 18 | Failed |
| 19 | } |
| 20 | |
| 21 | public sealed record WorkspaceRequest( |
| 22 | Guid JobId, |
| 23 | WorkspaceAction Action, |
| 24 | IReadOnlyList<string> Sources, |
| 25 | string? Destination = null) |
| 26 | { |
| 27 | public string Format { get; init; } = "zip"; |
| 28 | } |
| 29 | |
| 30 | public sealed record FileRow(string Name, string Size, string Verification) |
| 31 | { |
| 32 | public string EntryId { get; init; } = ""; |
| 33 | public EntryKind Kind { get; init; } |
| 34 | public EntryOutcome Outcome { get; init; } |
| 35 | public ArchiveError Error { get; init; } |
| 36 | } |
| 37 | |
| 38 | public sealed record WorkspaceProgress(long ProcessedBytes, long? TotalBytes) |
| 39 | { |
| 40 | public Guid JobId { get; init; } |
| 41 | public long Sequence { get; init; } |
| 42 | public JobState State { get; init; } = JobState.Running; |
| 43 | } |
| 44 | |
| 45 | public sealed record PasswordChallenge(Guid JobId, Guid RequestId) |
| 46 | { |
| 47 | public int Attempt { get; init; } = 1; |
| 48 | } |
| 49 | |
| 50 | public sealed record WorkspaceResult( |
| 51 | WorkspaceOutcome Outcome, |
| 52 | IReadOnlyList<FileRow> Entries) |
| 53 | { |
| 54 | public Guid JobId { get; init; } |
| 55 | public ArchiveError Error { get; init; } |
| 56 | public Zipelo.Ui.CreationResult? Creation { get; init; } |
| 57 | public Zipelo.Ui.ExtractionResult? Extraction { get; init; } |
| 58 | } |
| 59 | |
| 60 | // UI 측 연결 경계임. 실제 코어 계약과 연결하는 어댑터는 별도 구현함. |
| 61 | public interface IArchiveWorkspace |
| 62 | { |
| 63 | bool IsAvailable { get; } |
| 64 | |
| 65 | Task<WorkspaceResult> ExecuteAsync( |
| 66 | WorkspaceRequest request, |
| 67 | IProgress<WorkspaceProgress> progress, |
| 68 | Func<PasswordChallenge, CancellationToken, Task<SecureString?>> requestPassword, |
| 69 | CancellationToken cancellationToken); |
| 70 | } |
| 71 | |
| 72 | public sealed class UnavailableWorkspace : IArchiveWorkspace, IWorkspaceCapabilities |
| 73 | { |
| 74 | public bool IsAvailable => false; |
| 75 | public string AvailabilityMessage { get; internal set; } = |
| 76 | "작업 프로세스가 아직 연결되지 않았습니다. 파일을 처리할 수 없습니다."; |
| 77 | public bool CanExecute(WorkspaceAction action, string format) => false; |
| 78 | |
| 79 | public Task<WorkspaceResult> ExecuteAsync( |
| 80 | WorkspaceRequest request, |
| 81 | IProgress<WorkspaceProgress> progress, |
| 82 | Func<PasswordChallenge, CancellationToken, Task<SecureString?>> requestPassword, |
| 83 | CancellationToken cancellationToken) |
| 84 | { |
| 85 | throw new NotSupportedException("압축 엔진이 아직 연결되지 않았습니다."); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // 기능 조회는 실제 연결된 호스트가 제공함. 해제 검증 전에는 해제 능력을 게시하지 않음. |
| 90 | public interface IWorkspaceCapabilities |
| 91 | { |
| 92 | bool CanExecute(WorkspaceAction action, string format); |
| 93 | string AvailabilityMessage { get; } |
| 94 | } |