/**
 * Type Guard Functions for Moderation Queue
 * 
 * Provides runtime type checking for submission item data.
 * Enables type-safe handling of different entity types.
 */

import type {
  SubmissionItemData,
  ParkItemData,
  RideItemData,
  CompanyItemData,
  RideModelItemData,
  PhotoItemData,
} from '@/types/moderation';

/**
 * Check if item data is for a park
 */
export function isParkItemData(data: SubmissionItemData): data is ParkItemData {
  return 'park_type' in data && 'name' in data;
}

/**
 * Check if item data is for a ride
 */
export function isRideItemData(data: SubmissionItemData): data is RideItemData {
  return ('ride_id' in data || 'park_id' in data) && 'ride_type' in data;
}

/**
 * Check if item data is for a company
 */
export function isCompanyItemData(data: SubmissionItemData): data is CompanyItemData {
  return 'company_type' in data && !('park_type' in data) && !('ride_type' in data);
}

/**
 * Check if item data is for a ride model
 */
export function isRideModelItemData(data: SubmissionItemData): data is RideModelItemData {
  return 'model_type' in data && 'manufacturer_id' in data;
}

/**
 * Check if item data is for a photo
 */
export function isPhotoItemData(data: SubmissionItemData): data is PhotoItemData {
  return 'photo_url' in data;
}

/**
 * Get the entity type from item data (for validation and display)
 */
export function getEntityTypeFromItemData(data: SubmissionItemData): string {
  if (isParkItemData(data)) return 'park';
  if (isRideItemData(data)) return 'ride';
  if (isCompanyItemData(data)) {
    return data.company_type; // 'manufacturer', 'designer', etc.
  }
  if (isRideModelItemData(data)) return 'ride_model';
  if (isPhotoItemData(data)) return 'photo';
  return 'unknown';
}
