/**
 * Type-Safe Status Enums
 * Provides exhaustive type checking for all entity statuses
 */

import { z } from 'zod';

// Submission statuses
export type SubmissionStatus = 
  | 'draft'
  | 'pending'
  | 'locked'
  | 'reviewing'
  | 'partially_approved'
  | 'approved'
  | 'rejected'
  | 'escalated';

export const SubmissionStatusSchema = z.enum([
  'draft',
  'pending',
  'locked',
  'reviewing',
  'partially_approved',
  'approved',
  'rejected',
  'escalated'
]);

// Review statuses for individual items
export type ReviewStatus =
  | 'pending'
  | 'approved'
  | 'rejected'
  | 'flagged'
  | 'skipped';

export const ReviewStatusSchema = z.enum([
  'pending',
  'approved',
  'rejected',
  'flagged',
  'skipped'
]);

// Park operational statuses
export type ParkStatus =
  | 'operating'
  | 'closed_permanently'
  | 'closed_temporarily'
  | 'under_construction'
  | 'planned'
  | 'abandoned';

export const ParkStatusSchema = z.enum([
  'operating',
  'closed_permanently',
  'closed_temporarily',
  'under_construction',
  'planned',
  'abandoned'
]);

// Ride operational statuses
export type RideStatus =
  | 'operating'
  | 'closed_permanently'
  | 'closed_temporarily'
  | 'under_construction'
  | 'relocated'
  | 'stored'
  | 'demolished';

export const RideStatusSchema = z.enum([
  'operating',
  'closed_permanently',
  'closed_temporarily',
  'under_construction',
  'relocated',
  'stored',
  'demolished'
]);

// Account statuses
export type AccountStatus =
  | 'active'
  | 'suspended'
  | 'pending_deletion'
  | 'deleted';

export const AccountStatusSchema = z.enum([
  'active',
  'suspended',
  'pending_deletion',
  'deleted'
]);

// Lock statuses
export type LockStatus =
  | 'unlocked'
  | 'locked'
  | 'expired';

export const LockStatusSchema = z.enum([
  'unlocked',
  'locked',
  'expired'
]);

// Helper type guards
export function isSubmissionStatus(value: unknown): value is SubmissionStatus {
  return SubmissionStatusSchema.safeParse(value).success;
}

export function isReviewStatus(value: unknown): value is ReviewStatus {
  return ReviewStatusSchema.safeParse(value).success;
}

export function isParkStatus(value: unknown): value is ParkStatus {
  return ParkStatusSchema.safeParse(value).success;
}

export function isRideStatus(value: unknown): value is RideStatus {
  return RideStatusSchema.safeParse(value).success;
}

// Status display helpers
export const SUBMISSION_STATUS_LABELS: Record<SubmissionStatus, string> = {
  draft: 'Draft',
  pending: 'Pending Review',
  locked: 'Locked',
  reviewing: 'Under Review',
  partially_approved: 'Partially Approved',
  approved: 'Approved',
  rejected: 'Rejected',
  escalated: 'Escalated'
};

export const REVIEW_STATUS_LABELS: Record<ReviewStatus, string> = {
  pending: 'Pending',
  approved: 'Approved',
  rejected: 'Rejected',
  flagged: 'Flagged',
  skipped: 'Skipped'
};

export const PARK_STATUS_LABELS: Record<ParkStatus, string> = {
  operating: 'Operating',
  closed_permanently: 'Closed Permanently',
  closed_temporarily: 'Closed Temporarily',
  under_construction: 'Under Construction',
  planned: 'Planned',
  abandoned: 'Abandoned'
};

export const RIDE_STATUS_LABELS: Record<RideStatus, string> = {
  operating: 'Operating',
  closed_permanently: 'Closed Permanently',
  closed_temporarily: 'Closed Temporarily',
  under_construction: 'Under Construction',
  relocated: 'Relocated',
  stored: 'Stored',
  demolished: 'Demolished'
};
