using System; using System.Collections.Generic; using System.Threading.Tasks; using QuantEngine.Core.Interfaces; using QuantEngine.Core.Models; namespace QuantEngine.Application.Services { public class ApprovalService { private readonly IWorkspaceRepository _repository; public ApprovalService(IWorkspaceRepository repository) { _repository = repository; } public Task> GetApprovalsAsync() => _repository.GetApprovalsAsync(); public Task GetApprovalAsync(string domain, string targetRef) => _repository.GetApprovalAsync(RequireValue(domain, nameof(domain)), RequireValue(targetRef, nameof(targetRef))); public Task UpsertApprovalAsync(WorkspaceApproval approval) { ArgumentNullException.ThrowIfNull(approval); return _repository.UpsertApprovalAsync(approval); } public Task> GetLocksAsync() => _repository.GetLocksAsync(); public Task GetLockAsync(string domain, string targetRef) => _repository.GetLockAsync(RequireValue(domain, nameof(domain)), RequireValue(targetRef, nameof(targetRef))); public Task AcquireLockAsync(WorkspaceLock @lock) { ArgumentNullException.ThrowIfNull(@lock); return _repository.AcquireLockAsync(@lock); } public Task ReleaseLockAsync(string domain, string targetRef) => _repository.ReleaseLockAsync(RequireValue(domain, nameof(domain)), RequireValue(targetRef, nameof(targetRef))); private static string RequireValue(string value, string parameterName) { if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentException("Value is required.", parameterName); } return value.Trim(); } } }