using System.Text.Json.Serialization;
namespace PSLauncher.Models;
public sealed class LicenseValidationResponse
{
[JsonPropertyName("status")]
public string Status { get; set; } = "invalid";
[JsonPropertyName("licenseId")]
public string? LicenseId { get; set; }
[JsonPropertyName("ownerName")]
public string? OwnerName { get; set; }
[JsonPropertyName("issuedAt")]
public DateTime? IssuedAt { get; set; }
[JsonPropertyName("downloadEntitlementUntil")]
public DateTime? DownloadEntitlementUntil { get; set; }
[JsonPropertyName("maxMachines")]
public int? MaxMachines { get; set; }
///
/// Channel de manifest associé à la license. NULL = manifest default
/// (versions.json). Sinon le launcher fetch versions-{Channel}.json. Le
/// champ est inclus dans la signature Ed25519, donc un user ne peut pas
/// modifier sa réponse cachée pour basculer sur un autre channel.
///
[JsonPropertyName("channel")]
public string? Channel { get; set; }
///
/// True si la license autorise l'affichage des versions taggées
/// isBeta=true dans le launcher. Le filtrage est côté client (le
/// serveur peut servir le manifest complet — la signature Ed25519
/// protège contre toute modif locale du flag).
///
[JsonPropertyName("canSeeBetas")]
public bool CanSeeBetas { get; set; }
///
/// Hash SHA-256 (hex lowercase) du mot de passe qui verrouille les Settings
/// avancés du launcher. NULL = pas de verrouillage. Défini par-license dans
/// le backoffice (table licenses.settings_lock_password_hash) → permet
/// un mot de passe différent par client. Inclus dans la signature Ed25519.
///
[JsonPropertyName("settingsLockPasswordHash")]
public string? SettingsLockPasswordHash { get; set; }
[JsonPropertyName("serverTime")]
public DateTime? ServerTime { get; set; }
[JsonPropertyName("message")]
public string? Message { get; set; }
[JsonPropertyName("signature")]
public string? Signature { get; set; }
public bool IsValid => Status == "valid";
public bool IsExpired => Status == "expired";
public bool CanDownload(VersionManifest version)
{
if (!IsValid && !IsExpired) return false;
if (DownloadEntitlementUntil is null) return false;
if (version.MinLicenseDate is null) return true; // pas de minimum imposé
return DownloadEntitlementUntil >= version.MinLicenseDate;
}
}
public sealed class LicenseValidationRequest
{
[JsonPropertyName("licenseKey")] public string LicenseKey { get; set; } = string.Empty;
[JsonPropertyName("machineId")] public string MachineId { get; set; } = string.Empty;
[JsonPropertyName("machineLabel")] public string? MachineLabel { get; set; }
[JsonPropertyName("launcherVersion")] public string LauncherVersion { get; set; } = string.Empty;
}