namespace SharepointToolbox.Web.Core.Config;
///
/// The app's public domain (e.g. sptb.example.com or https://sptb.example.com),
/// configured via App__Domain. Used to derive the SharePoint-connect redirect URI when
/// isn't set explicitly.
///
public class AppDomainOptions
{
public string Domain { get; set; } = string.Empty;
///
/// Builds an absolute URL for rooted at the configured domain, or
/// null when no domain is set. Defaults to https when the domain has no scheme,
/// and tolerates accidental surrounding quotes / trailing slashes (docker-compose's list-form
/// env values can embed literal quotes).
///
public string? BuildUrl(string path)
{
var domain = Domain?.Trim().Trim('"', '\'').TrimEnd('/');
if (string.IsNullOrEmpty(domain))
return null;
if (!domain.Contains("://", StringComparison.Ordinal))
domain = "https://" + domain;
return domain + "/" + path.TrimStart('/');
}
///
/// The configured domain as an absolute base (scheme + host [+ port]), or
/// null when no domain is set or it can't be parsed.
///
public Uri? GetBaseUri() =>
BuildUrl("/") is { } url && Uri.TryCreate(url, UriKind.Absolute, out var uri) ? uri : null;
}