// packages/db/src/table-classification.ts
// Manual mapping of every Prisma model to a data-sensitivity level.
// Drives sanitized-clone obfuscation and export filtering.

export type TableSensitivity = "public" | "internal" | "confidential" | "restricted";

/**
 * Classification of all 195 Prisma models by data sensitivity.
 *
 * - public:       Reference / lookup data safe for any environment.
 * - internal:     Operational data with no PII — copy as-is to dev.
 * - confidential: Contains PII or customer data — obfuscate before copy.
 * - restricted:   Secrets, credentials, auth tokens — never copy.
 */
export const TABLE_CLASSIFICATION: Record<string, TableSensitivity> = {
  // -- public (15) --
  TaxonomyNode: "public",
  EaElementType: "public",
  EaRelationshipType: "public",
  EaRelationshipRule: "public",
  EaDqRule: "public",
  EaNotation: "public",
  EaStructureRule: "public",
  ViewpointDefinition: "public",
  StorefrontArchetype: "public",
  PlatformCapability: "public",
  Country: "public",
  Region: "public",
  City: "public",
  EmploymentType: "public",
  WorkLocation: "public",

  // -- internal (87) --
  Portfolio: "internal",
  DigitalProduct: "internal",
  ProductVersion: "internal",
  ChangePromotion: "internal",
  ChangeRequest: "internal",
  ChangeItem: "internal",
  DeploymentWindow: "internal",
  BlackoutPeriod: "internal",
  StandardChangeCatalog: "internal",
  CodebaseManifest: "internal",
  ServiceOffering: "internal",
  BacklogItem: "internal",
  Epic: "internal",
  EpicPortfolio: "internal",
  ImprovementProposal: "internal",
  BrandingConfig: "internal",
  EaReferenceModel: "internal",
  EaReferenceModelElement: "internal",
  EaReferenceModelArtifact: "internal",
  EaAssessmentScope: "internal",
  EaReferenceAssessment: "internal",
  EaReferenceProposal: "internal",
  EaElement: "internal",
  EaRelationship: "internal",
  EaView: "internal",
  EaViewElement: "internal",
  EaConformanceIssue: "internal",
  EaSnapshot: "internal",
  FeatureBuild: "internal",
  BuildActivity: "internal",
  PromotionBackup: "internal",
  FeaturePack: "internal",
  DiscoveryRun: "internal",
  DiscoveredItem: "internal",
  DiscoveredRelationship: "internal",
  InventoryEntity: "internal",
  InventoryRelationship: "internal",
  PortfolioQualityIssue: "internal",
  Regulation: "internal",
  Obligation: "internal",
  Control: "internal",
  ControlObligationLink: "internal",
  Policy: "internal",
  PolicyRequirement: "internal",
  PolicyObligationLink: "internal",
  TrainingRequirement: "internal",
  PolicyRule: "internal",
  ComplianceSnapshot: "internal",
  RegulatoryMonitorScan: "internal",
  RegulatoryAlert: "internal",
  Notification: "internal",
  DynamicForm: "internal",
  DynamicView: "internal",
  PlatformIssueReport: "internal",
  RuntimeAdvisory: "internal",
  PlatformSetupProgress: "internal",
  PlatformConfig: "internal",
  SelfUpgradeRun: "internal",
  ScheduledJob: "internal",
  McpServer: "internal",
  McpServerTool: "internal",
  McpIntegration: "internal",
  McpCatalogSync: "internal",
  StorefrontConfig: "internal",
  StorefrontSection: "internal",
  StorefrontItem: "internal",
  ProviderService: "internal",
  ProviderAvailability: "internal",
  OnboardingChecklist: "internal",
  OnboardingTask: "internal",
  OnboardingDraft: "internal",
  ReviewCycle: "internal",
  LeavePolicy: "internal",
  CalendarEvent: "internal",
  CalendarSync: "internal",
  ExecutionRecipe: "internal",
  RecurringSchedule: "internal",
  RecurringLineItem: "internal",
  DunningSequence: "internal",
  DunningStep: "internal",
  ExchangeRate: "internal",
  OrgSettings: "internal",
  ApprovalRule: "internal",
  BusinessProfile: "internal",

  // -- confidential (77) --
  User: "confidential",
  UserGroup: "confidential",
  CustomerContact: "confidential",
  SocialIdentity: "confidential",
  AccountInvite: "confidential",
  EmployeeProfile: "confidential",
  Department: "confidential",
  Position: "confidential",
  Address: "confidential",
  EmployeeAddress: "confidential",
  EmploymentEvent: "confidential",
  TerminationRecord: "confidential",
  Team: "confidential",
  TeamMembership: "confidential",
  Agent: "confidential",
  AgentOwnership: "confidential",
  AgentCapabilityClass: "confidential",
  DirectivePolicyClass: "confidential",
  AgentGovernanceProfile: "confidential",
  DelegationGrant: "confidential",
  AgentThread: "confidential",
  AgentMessage: "confidential",
  AgentActionProposal: "confidential",
  AgentAttachment: "confidential",
  CustomerAccount: "confidential",
  ContactAccountRole: "confidential",
  Organization: "confidential",
  Engagement: "confidential",
  Opportunity: "confidential",
  Quote: "confidential",
  QuoteLineItem: "confidential",
  SalesOrder: "confidential",
  Activity: "confidential",
  StorefrontBooking: "confidential",
  ServiceProvider: "confidential",
  BookingHold: "confidential",
  StorefrontOrder: "confidential",
  StorefrontInquiry: "confidential",
  StorefrontDonation: "confidential",
  Invoice: "confidential",
  InvoiceLineItem: "confidential",
  Payment: "confidential",
  PaymentAllocation: "confidential",
  Supplier: "confidential",
  Bill: "confidential",
  BillLineItem: "confidential",
  BillApproval: "confidential",
  PurchaseOrder: "confidential",
  PurchaseOrderLineItem: "confidential",
  BankAccount: "confidential",
  BankTransaction: "confidential",
  BankRule: "confidential",
  DunningLog: "confidential",
  ExpenseClaim: "confidential",
  ExpenseItem: "confidential",
  FixedAsset: "confidential",
  ReviewInstance: "confidential",
  ReviewGoal: "confidential",
  FeedbackNote: "confidential",
  LeaveBalance: "confidential",
  LeaveRequest: "confidential",
  TimesheetPeriod: "confidential",
  TimesheetEntry: "confidential",
  RequirementCompletion: "confidential",
  PolicyAcknowledgment: "confidential",
  ComplianceEvidence: "confidential",
  RiskAssessment: "confidential",
  RiskControl: "confidential",
  ComplianceIncident: "confidential",
  CorrectiveAction: "confidential",
  ComplianceAudit: "confidential",
  AuditFinding: "confidential",
  RegulatorySubmission: "confidential",
  PushDeviceRegistration: "confidential",
  ExternalEvidenceRecord: "confidential",
  AsyncInferenceOp: "confidential",
  TaskRun: "confidential",
  TaskNode: "confidential",
  TaskNodeEdge: "confidential",
  UserSkill: "confidential",
  TaskRequirement: "confidential",
  RouteDecisionLog: "confidential",
  CustomEvalDimension: "confidential",

  // -- restricted (16) --
  PasswordResetToken: "restricted",
  PlatformRole: "restricted",
  CredentialEntry: "restricted",
  OAuthPendingFlow: "restricted",
  ModelProvider: "restricted",
  DiscoveredModel: "restricted",
  ModelProfile: "restricted",
  TokenUsage: "restricted",
  EndpointTaskPerformance: "restricted",
  TaskEvaluation: "restricted",
  EndpointTestRun: "restricted",
  AuthorizationDecisionLog: "restricted",
  ComplianceAuditLog: "restricted",
  RouteOutcome: "restricted",
  RecipePerformance: "restricted",
  ApiToken: "restricted",
};

/** Fallback for tables not yet classified — defaults to confidential (obfuscate). */
export const DEFAULT_SENSITIVITY: TableSensitivity = "confidential";

/** Look up the sensitivity level for a table, falling back to DEFAULT_SENSITIVITY. */
export function getTableSensitivity(tableName: string): TableSensitivity {
  return TABLE_CLASSIFICATION[tableName] ?? DEFAULT_SENSITIVITY;
}
