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.15"
  }
  public: {
    Tables: {
      blog_posts: {
        Row: {
          author: string
          category: string
          content: string
          cover_image: string | null
          created_at: string
          excerpt: string
          id: string
          published: boolean
          published_at: string | null
          slug: string
          title: string
          updated_at: string
        }
        Insert: {
          author?: string
          category: string
          content: string
          cover_image?: string | null
          created_at?: string
          excerpt: string
          id?: string
          published?: boolean
          published_at?: string | null
          slug: string
          title: string
          updated_at?: string
        }
        Update: {
          author?: string
          category?: string
          content?: string
          cover_image?: string | null
          created_at?: string
          excerpt?: string
          id?: string
          published?: boolean
          published_at?: string | null
          slug?: string
          title?: string
          updated_at?: string
        }
        Relationships: []
      }
      chatbot_feedback: {
        Row: {
          answer: string | null
          created_at: string
          id: string
          message_ref: string | null
          question: string | null
          rating: string
        }
        Insert: {
          answer?: string | null
          created_at?: string
          id?: string
          message_ref?: string | null
          question?: string | null
          rating: string
        }
        Update: {
          answer?: string | null
          created_at?: string
          id?: string
          message_ref?: string | null
          question?: string | null
          rating?: string
        }
        Relationships: []
      }
      chatbot_knowledge: {
        Row: {
          category: string
          content: string
          created_at: string
          id: string
          kind: string
          published: boolean
          title: string
          updated_at: string
        }
        Insert: {
          category?: string
          content: string
          created_at?: string
          id?: string
          kind?: string
          published?: boolean
          title: string
          updated_at?: string
        }
        Update: {
          category?: string
          content?: string
          created_at?: string
          id?: string
          kind?: string
          published?: boolean
          title?: string
          updated_at?: string
        }
        Relationships: []
      }
      chatbud_conversations: {
        Row: {
          created_at: string
          id: string
          session_id: string
          title: string
          updated_at: string
          user_id: string | null
        }
        Insert: {
          created_at?: string
          id?: string
          session_id: string
          title?: string
          updated_at?: string
          user_id?: string | null
        }
        Update: {
          created_at?: string
          id?: string
          session_id?: string
          title?: string
          updated_at?: string
          user_id?: string | null
        }
        Relationships: []
      }
      chatbud_messages: {
        Row: {
          content: string
          conversation_id: string
          created_at: string
          id: string
          role: string
        }
        Insert: {
          content: string
          conversation_id: string
          created_at?: string
          id?: string
          role: string
        }
        Update: {
          content?: string
          conversation_id?: string
          created_at?: string
          id?: string
          role?: string
        }
        Relationships: [
          {
            foreignKeyName: "chatbud_messages_conversation_id_fkey"
            columns: ["conversation_id"]
            isOneToOne: false
            referencedRelation: "chatbud_conversations"
            referencedColumns: ["id"]
          },
        ]
      }
      contact_submission_events: {
        Row: {
          created_at: string
          email: string | null
          id: string
          ip_hash: string | null
          outcome: string
          reason: string | null
        }
        Insert: {
          created_at?: string
          email?: string | null
          id?: string
          ip_hash?: string | null
          outcome: string
          reason?: string | null
        }
        Update: {
          created_at?: string
          email?: string | null
          id?: string
          ip_hash?: string | null
          outcome?: string
          reason?: string | null
        }
        Relationships: []
      }
      contact_submissions: {
        Row: {
          company: string | null
          created_at: string
          email: string
          id: string
          internal_notes: string | null
          ip_hash: string | null
          message: string
          name: string
          source: string
          status: Database["public"]["Enums"]["lead_status"]
          updated_at: string
        }
        Insert: {
          company?: string | null
          created_at?: string
          email: string
          id?: string
          internal_notes?: string | null
          ip_hash?: string | null
          message: string
          name: string
          source?: string
          status?: Database["public"]["Enums"]["lead_status"]
          updated_at?: string
        }
        Update: {
          company?: string | null
          created_at?: string
          email?: string
          id?: string
          internal_notes?: string | null
          ip_hash?: string | null
          message?: string
          name?: string
          source?: string
          status?: Database["public"]["Enums"]["lead_status"]
          updated_at?: string
        }
        Relationships: []
      }
      course_enrollments: {
        Row: {
          completed_lessons: Json
          course_id: string
          created_at: string
          id: string
          user_id: string
        }
        Insert: {
          completed_lessons?: Json
          course_id: string
          created_at?: string
          id?: string
          user_id: string
        }
        Update: {
          completed_lessons?: Json
          course_id?: string
          created_at?: string
          id?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "course_enrollments_course_id_fkey"
            columns: ["course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      courses: {
        Row: {
          category: string
          created_at: string
          duration_hours: number
          id: string
          level: string
          published: boolean
          slug: string
          summary: string
          title: string
        }
        Insert: {
          category?: string
          created_at?: string
          duration_hours?: number
          id?: string
          level?: string
          published?: boolean
          slug: string
          summary?: string
          title: string
        }
        Update: {
          category?: string
          created_at?: string
          duration_hours?: number
          id?: string
          level?: string
          published?: boolean
          slug?: string
          summary?: string
          title?: string
        }
        Relationships: []
      }
      finance_audit_log: {
        Row: {
          action: string
          actor_email: string | null
          actor_id: string | null
          created_at: string
          details: Json
          entity: string
          entity_id: string | null
          id: string
        }
        Insert: {
          action: string
          actor_email?: string | null
          actor_id?: string | null
          created_at?: string
          details?: Json
          entity: string
          entity_id?: string | null
          id?: string
        }
        Update: {
          action?: string
          actor_email?: string | null
          actor_id?: string | null
          created_at?: string
          details?: Json
          entity?: string
          entity_id?: string | null
          id?: string
        }
        Relationships: []
      }
      finance_receipts: {
        Row: {
          amount: number
          created_at: string
          currency: string
          id: string
          issued_by: string | null
          issued_on: string
          issued_to: string
          issued_to_email: string | null
          items: Json
          method: string
          notes: string | null
          receipt_no: string
          transaction_id: string | null
          updated_at: string
        }
        Insert: {
          amount: number
          created_at?: string
          currency?: string
          id?: string
          issued_by?: string | null
          issued_on?: string
          issued_to: string
          issued_to_email?: string | null
          items?: Json
          method?: string
          notes?: string | null
          receipt_no?: string
          transaction_id?: string | null
          updated_at?: string
        }
        Update: {
          amount?: number
          created_at?: string
          currency?: string
          id?: string
          issued_by?: string | null
          issued_on?: string
          issued_to?: string
          issued_to_email?: string | null
          items?: Json
          method?: string
          notes?: string | null
          receipt_no?: string
          transaction_id?: string | null
          updated_at?: string
        }
        Relationships: [
          {
            foreignKeyName: "finance_receipts_transaction_id_fkey"
            columns: ["transaction_id"]
            isOneToOne: false
            referencedRelation: "finance_transactions"
            referencedColumns: ["id"]
          },
        ]
      }
      finance_transactions: {
        Row: {
          amount: number
          category: string
          counterparty: string | null
          created_at: string
          created_by: string | null
          currency: string
          description: string
          direction: string
          id: string
          method: string
          occurred_on: string
          reference: string | null
          updated_at: string
        }
        Insert: {
          amount: number
          category?: string
          counterparty?: string | null
          created_at?: string
          created_by?: string | null
          currency?: string
          description: string
          direction: string
          id?: string
          method?: string
          occurred_on?: string
          reference?: string | null
          updated_at?: string
        }
        Update: {
          amount?: number
          category?: string
          counterparty?: string | null
          created_at?: string
          created_by?: string | null
          currency?: string
          description?: string
          direction?: string
          id?: string
          method?: string
          occurred_on?: string
          reference?: string | null
          updated_at?: string
        }
        Relationships: []
      }
      lessons: {
        Row: {
          content: string
          course_id: string
          duration_minutes: number
          id: string
          position: number
          title: string
        }
        Insert: {
          content?: string
          course_id: string
          duration_minutes?: number
          id?: string
          position?: number
          title: string
        }
        Update: {
          content?: string
          course_id?: string
          duration_minutes?: number
          id?: string
          position?: number
          title?: string
        }
        Relationships: [
          {
            foreignKeyName: "lessons_course_id_fkey"
            columns: ["course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      mail_messages: {
        Row: {
          attachments: Json
          body: string
          created_at: string
          folder: string
          from_email: string
          id: string
          read: boolean
          starred: boolean
          subject: string
          to_emails: string[]
          user_id: string
        }
        Insert: {
          attachments?: Json
          body?: string
          created_at?: string
          folder?: string
          from_email: string
          id?: string
          read?: boolean
          starred?: boolean
          subject?: string
          to_emails?: string[]
          user_id: string
        }
        Update: {
          attachments?: Json
          body?: string
          created_at?: string
          folder?: string
          from_email?: string
          id?: string
          read?: boolean
          starred?: boolean
          subject?: string
          to_emails?: string[]
          user_id?: string
        }
        Relationships: []
      }
      podcast_episodes: {
        Row: {
          audio_url: string | null
          cover_image_url: string | null
          created_at: string
          duration_minutes: number
          id: string
          published: boolean
          published_at: string
          show_notes: string
          slug: string
          summary: string
          title: string
          updated_at: string
          video_url: string | null
        }
        Insert: {
          audio_url?: string | null
          cover_image_url?: string | null
          created_at?: string
          duration_minutes?: number
          id?: string
          published?: boolean
          published_at?: string
          show_notes?: string
          slug: string
          summary?: string
          title: string
          updated_at?: string
          video_url?: string | null
        }
        Update: {
          audio_url?: string | null
          cover_image_url?: string | null
          created_at?: string
          duration_minutes?: number
          id?: string
          published?: boolean
          published_at?: string
          show_notes?: string
          slug?: string
          summary?: string
          title?: string
          updated_at?: string
          video_url?: string | null
        }
        Relationships: []
      }
      podcast_guests: {
        Row: {
          avatar_url: string | null
          bio: string
          created_at: string
          episode_id: string | null
          id: string
          link_url: string | null
          name: string
          published: boolean
          role_title: string
        }
        Insert: {
          avatar_url?: string | null
          bio?: string
          created_at?: string
          episode_id?: string | null
          id?: string
          link_url?: string | null
          name: string
          published?: boolean
          role_title?: string
        }
        Update: {
          avatar_url?: string | null
          bio?: string
          created_at?: string
          episode_id?: string | null
          id?: string
          link_url?: string | null
          name?: string
          published?: boolean
          role_title?: string
        }
        Relationships: [
          {
            foreignKeyName: "podcast_guests_episode_id_fkey"
            columns: ["episode_id"]
            isOneToOne: false
            referencedRelation: "podcast_episodes"
            referencedColumns: ["id"]
          },
        ]
      }
      podcast_questions: {
        Row: {
          answer: string | null
          created_at: string
          display_name: string
          episode_id: string | null
          id: string
          question: string
          status: string
        }
        Insert: {
          answer?: string | null
          created_at?: string
          display_name: string
          episode_id?: string | null
          id?: string
          question: string
          status?: string
        }
        Update: {
          answer?: string | null
          created_at?: string
          display_name?: string
          episode_id?: string | null
          id?: string
          question?: string
          status?: string
        }
        Relationships: [
          {
            foreignKeyName: "podcast_questions_episode_id_fkey"
            columns: ["episode_id"]
            isOneToOne: false
            referencedRelation: "podcast_episodes"
            referencedColumns: ["id"]
          },
        ]
      }
      podcast_schedule: {
        Row: {
          created_at: string
          duration_minutes: number
          id: string
          published: boolean
          starts_at: string
          status: string
          stream_url: string | null
          title: string
          topic: string
          updated_at: string
        }
        Insert: {
          created_at?: string
          duration_minutes?: number
          id?: string
          published?: boolean
          starts_at: string
          status?: string
          stream_url?: string | null
          title: string
          topic?: string
          updated_at?: string
        }
        Update: {
          created_at?: string
          duration_minutes?: number
          id?: string
          published?: boolean
          starts_at?: string
          status?: string
          stream_url?: string | null
          title?: string
          topic?: string
          updated_at?: string
        }
        Relationships: []
      }
      podcast_subscribers: {
        Row: {
          browser_push: boolean
          created_at: string
          email: string
          id: string
        }
        Insert: {
          browser_push?: boolean
          created_at?: string
          email: string
          id?: string
        }
        Update: {
          browser_push?: boolean
          created_at?: string
          email?: string
          id?: string
        }
        Relationships: []
      }
      studio_generations: {
        Row: {
          created_at: string
          id: string
          kind: string
          output: string
          prompt: string
          user_id: string
        }
        Insert: {
          created_at?: string
          id?: string
          kind: string
          output?: string
          prompt: string
          user_id: string
        }
        Update: {
          created_at?: string
          id?: string
          kind?: string
          output?: string
          prompt?: string
          user_id?: string
        }
        Relationships: []
      }
      studio_requests: {
        Row: {
          created_at: string
          details: string
          id: string
          kind: string
          output_url: string | null
          status: string
          title: string
          user_id: string
        }
        Insert: {
          created_at?: string
          details?: string
          id?: string
          kind: string
          output_url?: string | null
          status?: string
          title: string
          user_id: string
        }
        Update: {
          created_at?: string
          details?: string
          id?: string
          kind?: string
          output_url?: string | null
          status?: string
          title?: string
          user_id?: string
        }
        Relationships: []
      }
      user_roles: {
        Row: {
          created_at: string
          id: string
          role: Database["public"]["Enums"]["app_role"]
          user_id: string
        }
        Insert: {
          created_at?: string
          id?: string
          role: Database["public"]["Enums"]["app_role"]
          user_id: string
        }
        Update: {
          created_at?: string
          id?: string
          role?: Database["public"]["Enums"]["app_role"]
          user_id?: string
        }
        Relationships: []
      }
    }
    Views: {
      [_ in never]: never
    }
    Functions: {
      contact_rate_limited: {
        Args: { _email: string; _ip_hash: string }
        Returns: boolean
      }
      has_role: {
        Args: {
          _role: Database["public"]["Enums"]["app_role"]
          _user_id: string
        }
        Returns: boolean
      }
      is_finance_member: { Args: { _user_id: string }; Returns: boolean }
      log_contact_event: {
        Args: {
          _email: string
          _ip_hash: string
          _outcome: string
          _reason: string
        }
        Returns: undefined
      }
    }
    Enums: {
      app_role: "admin" | "editor" | "user" | "finance"
      lead_status: "new" | "contacted" | "qualified" | "archived"
    }
    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: {
      app_role: ["admin", "editor", "user", "finance"],
      lead_status: ["new", "contacted", "qualified", "archived"],
    },
  },
} as const
