export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json | undefined }
  | Json[]

export type Database = {
  // Allows to automatically instantiate createClient with right options
  // instead of createClient<Database, { PostgrestVersion: 'XX' }>(URL, KEY)
  __InternalSupabase: {
    PostgrestVersion: "14.4"
  }
  public: {
    Tables: {
      no_show_events: {
        Row: {
          created_at: string | null
          detected_at: string | null
          id: string
          notified_at: string | null
          reservation_id: string
          user_id: string
        }
        Insert: {
          created_at?: string | null
          detected_at?: string | null
          id?: string
          notified_at?: string | null
          reservation_id: string
          user_id: string
        }
        Update: {
          created_at?: string | null
          detected_at?: string | null
          id?: string
          notified_at?: string | null
          reservation_id?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "no_show_events_reservation_id_fkey"
            columns: ["reservation_id"]
            isOneToOne: false
            referencedRelation: "reservations"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "no_show_events_user_id_fkey"
            columns: ["user_id"]
            isOneToOne: false
            referencedRelation: "users"
            referencedColumns: ["id"]
          },
        ]
      }
      // offices table removed — locations hierarchy replaces it
      reservations: {
        Row: {
          checked_in_at: string | null
          created_at: string | null
          end_at: string
          id: string
          notes: string | null
          resource_id: string
          start_at: string
          status: string | null
          updated_at: string | null
          user_id: string
        }
        Insert: {
          checked_in_at?: string | null
          created_at?: string | null
          end_at: string
          id?: string
          notes?: string | null
          resource_id: string
          start_at: string
          status?: string | null
          updated_at?: string | null
          user_id: string
        }
        Update: {
          checked_in_at?: string | null
          created_at?: string | null
          end_at?: string
          id?: string
          notes?: string | null
          resource_id?: string
          start_at?: string
          status?: string | null
          updated_at?: string | null
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "reservations_resource_id_fkey"
            columns: ["resource_id"]
            isOneToOne: false
            referencedRelation: "resources"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "reservations_user_id_fkey"
            columns: ["user_id"]
            isOneToOne: false
            referencedRelation: "users"
            referencedColumns: ["id"]
          },
        ]
      }
      resource_policies: {
        Row: {
          auto_cancel_no_show: boolean | null
          available_days: number[] | null
          available_end_time: string | null
          available_start_time: string | null
          check_in_window_minutes: number | null
          created_at: string | null
          id: string
          max_advance_days: number | null
          max_duration_minutes: number | null
          min_advance_minutes: number | null
          min_duration_minutes: number | null
          resource_id: string | null
          resource_type_id: string | null
          updated_at: string | null
        }
        Insert: {
          auto_cancel_no_show?: boolean | null
          available_days?: number[] | null
          available_end_time?: string | null
          available_start_time?: string | null
          check_in_window_minutes?: number | null
          created_at?: string | null
          id?: string
          max_advance_days?: number | null
          max_duration_minutes?: number | null
          min_advance_minutes?: number | null
          min_duration_minutes?: number | null
          resource_id?: string | null
          resource_type_id?: string | null
          updated_at?: string | null
        }
        Update: {
          auto_cancel_no_show?: boolean | null
          available_days?: number[] | null
          available_end_time?: string | null
          available_start_time?: string | null
          check_in_window_minutes?: number | null
          created_at?: string | null
          id?: string
          max_advance_days?: number | null
          max_duration_minutes?: number | null
          min_advance_minutes?: number | null
          min_duration_minutes?: number | null
          resource_id?: string | null
          resource_type_id?: string | null
          updated_at?: string | null
        }
        Relationships: [
          {
            foreignKeyName: "resource_policies_resource_id_fkey"
            columns: ["resource_id"]
            isOneToOne: false
            referencedRelation: "resources"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "resource_policies_resource_type_id_fkey"
            columns: ["resource_type_id"]
            isOneToOne: false
            referencedRelation: "resource_types"
            referencedColumns: ["id"]
          },
        ]
      }
      resource_types: {
        Row: {
          booking_unit: "hour" | "day"
          booking_window_start: string
          booking_window_end: string
          created_at: string | null
          description: string | null
          icon: string | null
          id: string
          is_active: boolean | null
          name: string
          slot_size: "15min" | "30min" | "1h"
          slug: string
          time_granularity: "5min" | "10min" | "15min" | "30min" | "60min"
        }
        Insert: {
          booking_unit?: "hour" | "day"
          booking_window_start?: string
          booking_window_end?: string
          created_at?: string | null
          description?: string | null
          icon?: string | null
          id?: string
          is_active?: boolean | null
          name: string
          slot_size?: "15min" | "30min" | "1h"
          slug: string
          time_granularity?: "5min" | "10min" | "15min" | "30min" | "60min"
        }
        Update: {
          booking_unit?: "hour" | "day"
          booking_window_start?: string
          booking_window_end?: string
          created_at?: string | null
          description?: string | null
          icon?: string | null
          id?: string
          is_active?: boolean | null
          name?: string
          slot_size?: "15min" | "30min" | "1h"
          slug?: string
          time_granularity?: "5min" | "10min" | "15min" | "30min" | "60min"
        }
        Relationships: []
      }
      resources: {
        Row: {
          amenities: Json | null
          capacity: number | null
          created_at: string | null
          description: string | null
          floor: string | null
          id: string
          is_active: boolean | null
          metadata: Json | null
          name: string
          resource_type_id: string
          updated_at: string | null
        }
        Insert: {
          amenities?: Json | null
          capacity?: number | null
          created_at?: string | null
          description?: string | null
          floor?: string | null
          id?: string
          is_active?: boolean | null
          metadata?: Json | null
          name: string
          resource_type_id: string
          updated_at?: string | null
        }
        Update: {
          amenities?: Json | null
          capacity?: number | null
          created_at?: string | null
          description?: string | null
          floor?: string | null
          id?: string
          is_active?: boolean | null
          metadata?: Json | null
          name?: string
          resource_type_id?: string
          updated_at?: string | null
        }
        Relationships: [
          {
            foreignKeyName: "resources_resource_type_id_fkey"
            columns: ["resource_type_id"]
            isOneToOne: false
            referencedRelation: "resource_types"
            referencedColumns: ["id"]
          },
        ]
      }
      users: {
        Row: {
          created_at: string | null
          email: string
          full_name: string | null
          id: string
          is_active: boolean | null
          role: string | null
          updated_at: string | null
        }
        Insert: {
          created_at?: string | null
          email: string
          full_name?: string | null
          id: string
          is_active?: boolean | null
          role?: string | null
          updated_at?: string | null
        }
        Update: {
          created_at?: string | null
          email?: string
          full_name?: string | null
          id?: string
          is_active?: boolean | null
          role?: string | null
          updated_at?: string | null
        }
        Relationships: []
      }
    }
    Views: {
      [_ in never]: never
    }
    Functions: {
      [_ in never]: never
    }
    Enums: {
      [_ in never]: never
    }
    CompositeTypes: {
      [_ in never]: never
    }
  }
}

type DatabaseWithoutInternals = Omit<Database, "__InternalSupabase">

type DefaultSchema = DatabaseWithoutInternals[Extract<keyof Database, "public">]

export type Tables<
  DefaultSchemaTableNameOrOptions extends
    | keyof (DefaultSchema["Tables"] & DefaultSchema["Views"])
    | { schema: keyof DatabaseWithoutInternals },
  TableName extends DefaultSchemaTableNameOrOptions extends {
    schema: keyof DatabaseWithoutInternals
  }
    ? keyof (DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] &
        DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Views"])
    : never = never,
> = DefaultSchemaTableNameOrOptions extends {
  schema: keyof DatabaseWithoutInternals
}
  ? (DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] &
      DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Views"])[TableName] extends {
      Row: infer R
    }
    ? R
    : never
  : DefaultSchemaTableNameOrOptions extends keyof (DefaultSchema["Tables"] &
        DefaultSchema["Views"])
    ? (DefaultSchema["Tables"] &
        DefaultSchema["Views"])[DefaultSchemaTableNameOrOptions] extends {
        Row: infer R
      }
      ? R
      : never
    : never

export type TablesInsert<
  DefaultSchemaTableNameOrOptions extends
    | keyof DefaultSchema["Tables"]
    | { schema: keyof DatabaseWithoutInternals },
  TableName extends DefaultSchemaTableNameOrOptions extends {
    schema: keyof DatabaseWithoutInternals
  }
    ? keyof DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"]
    : never = never,
> = DefaultSchemaTableNameOrOptions extends {
  schema: keyof DatabaseWithoutInternals
}
  ? DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends {
      Insert: infer I
    }
    ? I
    : never
  : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"]
    ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends {
        Insert: infer I
      }
      ? I
      : never
    : never

export type TablesUpdate<
  DefaultSchemaTableNameOrOptions extends
    | keyof DefaultSchema["Tables"]
    | { schema: keyof DatabaseWithoutInternals },
  TableName extends DefaultSchemaTableNameOrOptions extends {
    schema: keyof DatabaseWithoutInternals
  }
    ? keyof DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"]
    : never = never,
> = DefaultSchemaTableNameOrOptions extends {
  schema: keyof DatabaseWithoutInternals
}
  ? DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends {
      Update: infer U
    }
    ? U
    : never
  : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"]
    ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends {
        Update: infer U
      }
      ? U
      : never
    : never

export type Enums<
  DefaultSchemaEnumNameOrOptions extends
    | keyof DefaultSchema["Enums"]
    | { schema: keyof DatabaseWithoutInternals },
  EnumName extends DefaultSchemaEnumNameOrOptions extends {
    schema: keyof DatabaseWithoutInternals
  }
    ? keyof DatabaseWithoutInternals[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"]
    : never = never,
> = DefaultSchemaEnumNameOrOptions extends {
  schema: keyof DatabaseWithoutInternals
}
  ? DatabaseWithoutInternals[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"][EnumName]
  : DefaultSchemaEnumNameOrOptions extends keyof DefaultSchema["Enums"]
    ? DefaultSchema["Enums"][DefaultSchemaEnumNameOrOptions]
    : never

export type CompositeTypes<
  PublicCompositeTypeNameOrOptions extends
    | keyof DefaultSchema["CompositeTypes"]
    | { schema: keyof DatabaseWithoutInternals },
  CompositeTypeName extends PublicCompositeTypeNameOrOptions extends {
    schema: keyof DatabaseWithoutInternals
  }
    ? keyof DatabaseWithoutInternals[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"]
    : never = never,
> = PublicCompositeTypeNameOrOptions extends {
  schema: keyof DatabaseWithoutInternals
}
  ? DatabaseWithoutInternals[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName]
  : PublicCompositeTypeNameOrOptions extends keyof DefaultSchema["CompositeTypes"]
    ? DefaultSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions]
    : never

export const Constants = {
  public: {
    Enums: {},
  },
} as const

// Helper types for easier usage
export type User = Tables<"users">
export type ResourceType = Tables<"resource_types">
export type Resource = Tables<"resources">
export type Reservation = Tables<"reservations">
export type ResourcePolicy = Tables<"resource_policies">
export type NoShowEvent = Tables<"no_show_events">
