mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-02-20 07:46:34 -05:00
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System;
|
|
|
|
using Cleanuparr.Domain.Enums;
|
|
using Cleanuparr.Domain.Exceptions;
|
|
using Cleanuparr.Persistence.Models.Configuration;
|
|
|
|
namespace Cleanuparr.Api.Features.DownloadClient.Contracts.Requests;
|
|
|
|
public sealed record TestDownloadClientRequest
|
|
{
|
|
public DownloadClientTypeName TypeName { get; init; }
|
|
|
|
public DownloadClientType Type { get; init; }
|
|
|
|
public string? Host { get; init; }
|
|
|
|
public string? Username { get; init; }
|
|
|
|
public string? Password { get; init; }
|
|
|
|
public string? UrlBase { get; init; }
|
|
|
|
public void Validate()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Host))
|
|
{
|
|
throw new ValidationException("Host cannot be empty");
|
|
}
|
|
|
|
if (!Uri.TryCreate(Host, UriKind.RelativeOrAbsolute, out _))
|
|
{
|
|
throw new ValidationException("Host is not a valid URL");
|
|
}
|
|
}
|
|
|
|
public DownloadClientConfig ToTestConfig() => new()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Enabled = true,
|
|
Name = "Test Client",
|
|
TypeName = TypeName,
|
|
Type = Type,
|
|
Host = new Uri(Host!, UriKind.RelativeOrAbsolute),
|
|
Username = Username,
|
|
Password = Password,
|
|
UrlBase = UrlBase,
|
|
};
|
|
}
|