/**
 * Company Data Types
 * 
 * Type-safe interfaces for company database records and form data.
 * These types prevent `as any` casts when working with company entities.
 */

export interface CompanyDatabaseRecord {
  id: string;
  name: string;
  slug: string;
  description?: string | null;
  company_type: 'manufacturer' | 'designer' | 'operator' | 'property_owner';
  person_type: 'company' | 'individual' | 'firm' | 'organization';
  website_url?: string | null;
  founded_year?: number | null;
  headquarters_location?: string | null;
  logo_url?: string | null;
  banner_image_url?: string | null;
  card_image_url?: string | null;
  created_at: string;
  updated_at: string;
  // Stats fields
  total_rides?: number;
  average_rating?: number;
  review_count?: number;
}

export interface TimelineEventDatabaseRecord {
  id: string;
  entity_id: string;
  entity_type: 'park' | 'ride' | 'company' | 'ride_model';
  event_type: string;
  event_date: string;
  event_date_precision: 'day' | 'month' | 'year';
  title: string;
  description?: string | null;
  from_value?: string | null;
  to_value?: string | null;
  from_entity_id?: string | null;
  to_entity_id?: string | null;
  from_location_id?: string | null;
  to_location_id?: string | null;
  display_order: number;
  created_by?: string | null;
  approved_by?: string | null;
  submission_id?: string | null;
  created_at: string;
  updated_at: string;
}

export interface LocationData {
  country?: string;
  state_province?: string;
  city?: string;
  latitude?: number;
  longitude?: number;
}

/**
 * Type guard for company database records
 */
export function isCompanyRecord(data: unknown): data is CompanyDatabaseRecord {
  return (
    typeof data === 'object' &&
    data !== null &&
    'id' in data &&
    'name' in data &&
    'company_type' in data
  );
}

/**
 * Type guard for timeline event records
 */
export function isTimelineEventRecord(data: unknown): data is TimelineEventDatabaseRecord {
  return (
    typeof data === 'object' &&
    data !== null &&
    'id' in data &&
    'entity_type' in data &&
    'event_type' in data
  );
}
