using Flurl.Http; namespace Recyclarr.ServarrApi.QualityProfile; internal class QualityProfileApiService(IServarrRequestBuilder service) : IQualityProfileApiService { private IFlurlRequest Request(params object[] path) { return service.Request(["qualityprofile", ..path]); } public async Task> GetQualityProfiles(CancellationToken ct) { var response = await Request() .GetJsonAsync>(cancellationToken: ct); return response.Select(x => x.ReverseItems()).ToList(); } public async Task GetSchema(CancellationToken ct) { var response = await Request("schema") .GetJsonAsync(cancellationToken: ct); return response.ReverseItems(); } public async Task UpdateQualityProfile(QualityProfileDto profile, CancellationToken ct) { if (profile.Id is null) { throw new ArgumentException($"Profile's ID property must not be null: {profile.Name}"); } await Request(profile.Id) .PutJsonAsync(profile.ReverseItems(), cancellationToken: ct); } public async Task CreateQualityProfile(QualityProfileDto profile, CancellationToken ct) { var response = await Request() .PostJsonAsync(profile.ReverseItems(), cancellationToken: ct) .ReceiveJson(); profile.Id = response.Id; } }