namespace EntitlementDAL.DTOs;
// ── Provisioning service contracts ──────────────────────────────────────────
///
/// Request for IProvisioningService.ProvisionSubscriptionAsync. Idempotency key is
/// IdmsEngagementRef — a repeat call with the same ref is a no-op that returns the
/// existing subscription's result rather than creating a duplicate.
///
public class ProvisionSubscriptionRequest
{
public int ClientId { get; set; }
public int PlanId { get; set; }
public string IdmsEngagementRef { get; set; } = string.Empty;
public bool TrialFlag { get; set; }
public DateTime? TrialEndDate { get; set; }
public DateTime StartDate { get; set; } = DateTime.UtcNow;
public DateTime LicenseValidTill { get; set; }
public DateTime SupportValidTill { get; set; }
}
public class ProvisioningResultDto
{
public int SubscriptionId { get; set; }
public int ClientId { get; set; }
public bool AlreadyExisted { get; set; } // true when idempotent replay short-circuited
public string Status { get; set; } = string.Empty;
}
///
/// Richer status contract (upgraded from a bare SubscriptionStatus read) backed by
/// MPROVISIONINGJOB. Status is "not_found" when no job exists for the client yet.
/// ProgressPct/CompletedSteps only reflect what's actually automated today (subscription
/// creation + entitlement seeding) — not the full future 8-step Quickstart pipeline.
///
public class ProvisioningStatusDto
{
public int ClientId { get; set; }
public string Status { get; set; } = "not_found"; // queued | running | completed | failed | partial_fail | not_found
public string CurrentStep { get; set; } = string.Empty;
public string[] CompletedSteps { get; set; } = Array.Empty();
public int ProgressPct { get; set; }
public string? ErrorMessage { get; set; }
public bool CanRetry { get; set; }
public string? DockerPackageUrl { get; set; }
}
// ── Subscription service contracts ──────────────────────────────────────────
public class SaveSubscriptionRequest
{
public int SubscriptionId { get; set; } // 0 = new
public int ClientId { get; set; }
public int PlanId { get; set; }
public string IdmsEngagementRef { get; set; } = string.Empty;
public bool TrialFlag { get; set; }
public DateTime? TrialEndDate { get; set; }
public DateTime StartDate { get; set; }
public DateTime LicenseValidTill { get; set; }
public DateTime SupportValidTill { get; set; }
public DateTime HostingValidTill { get; set; }
public int GracePeriodDays { get; set; } = 30;
public bool AutoRenew { get; set; }
public string? Remarks { get; set; }
}
/// Read-shape returned by ISubscriptionService.GetAsync/SaveAsync.
public class SubscriptionResultDto
{
public int SubscriptionId { get; set; }
public int ClientId { get; set; }
public int PlanId { get; set; }
public string PlanCode { get; set; } = string.Empty;
public string IdmsEngagementRef { get; set; } = string.Empty;
public byte SubscriptionStatus { get; set; }
public bool TrialFlag { get; set; }
public DateTime? TrialEndDate { get; set; }
public DateTime StartDate { get; set; }
public DateTime LicenseValidTill { get; set; }
public DateTime SupportValidTill { get; set; }
public DateTime HostingValidTill { get; set; }
public int GracePeriodDays { get; set; }
public bool AutoRenew { get; set; }
public int? PayOrderId { get; set; }
}
// Alias kept for readability against the plan's own naming ("SubscriptionDto") —
// intentionally identical shape to SubscriptionResultDto to avoid a second maintained type.
public class SubscriptionDto : SubscriptionResultDto { }
// Combined snapshot for a system-to-system caller (SqlWorkbench's rollout/provisioning gating,
// tracker §40) that needs one round trip to answer both Gate A (subscription/support/deployment
// eligibility) and Gate B (feature/module licensing) questions, rather than three separate calls
// against Subscription.svc/Plan.svc/a client-lookup that doesn't exist yet on the caller's side.
public class ClientEntitlementSnapshotDTO
{
public int ClientId { get; set; }
public byte SubscriptionStatus { get; set; }
public DateTime SupportValidTill { get; set; }
public int GracePeriodDays { get; set; }
// GB5Shared.Enums.Client.ClientDeploymentType (SaaS=0/OnPrem=1/BYOCloud=2/Hybrid=3). Not
// referenced as the real enum type here — EntitlementDAL has no dependency on that
// GB5Shared.Enums namespace today, and this DTO crosses an HTTP boundary as a plain byte
// regardless, so a raw byte avoids adding a new, narrow cross-project reference for one field.
public byte DeploymentType { get; set; }
// Feature codes enabled on the client's current Plan (MENTITLEMENTPLANFEATURE.ISENABLED=1) —
// Gate B checks a package's RequiredFeatureCode against this list.
public List EnabledFeatureCodes { get; set; } = new();
}