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.5"
  }
  public: {
    Tables: {
      assessment_categories: {
        Row: {
          code: string | null
          description: string
          id: string
          name: string
          slug: string
          sort_order: number
        }
        Insert: {
          code?: string | null
          description: string
          id?: string
          name: string
          slug: string
          sort_order?: number
        }
        Update: {
          code?: string | null
          description?: string
          id?: string
          name?: string
          slug?: string
          sort_order?: number
        }
        Relationships: []
      }
      assessment_questions: {
        Row: {
          category_id: string
          id: string
          prompt: string
          sort_order: number
        }
        Insert: {
          category_id: string
          id?: string
          prompt: string
          sort_order?: number
        }
        Update: {
          category_id?: string
          id?: string
          prompt?: string
          sort_order?: number
        }
        Relationships: [
          {
            foreignKeyName: "assessment_questions_category_id_fkey"
            columns: ["category_id"]
            isOneToOne: false
            referencedRelation: "assessment_categories"
            referencedColumns: ["id"]
          },
        ]
      }
      assessment_responses: {
        Row: {
          created_at: string
          id: string
          question_id: string
          score: number
          updated_at: string
          user_id: string
        }
        Insert: {
          created_at?: string
          id?: string
          question_id: string
          score: number
          updated_at?: string
          user_id: string
        }
        Update: {
          created_at?: string
          id?: string
          question_id?: string
          score?: number
          updated_at?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "assessment_responses_question_id_fkey"
            columns: ["question_id"]
            isOneToOne: false
            referencedRelation: "assessment_questions"
            referencedColumns: ["id"]
          },
        ]
      }
      assessment_results: {
        Row: {
          category_scores: Json
          created_at: string
          id: string
          level: string
          overall_score: number
          user_id: string
        }
        Insert: {
          category_scores?: Json
          created_at?: string
          id?: string
          level: string
          overall_score: number
          user_id: string
        }
        Update: {
          category_scores?: Json
          created_at?: string
          id?: string
          level?: string
          overall_score?: number
          user_id?: string
        }
        Relationships: []
      }
      certificates: {
        Row: {
          assessment_score: number | null
          business_name: string | null
          certificate_number: string
          certificate_type: string
          course_id: string
          course_title: string
          created_at: string
          credential_level: string
          id: string
          issued_at: string
          learner_name: string
          learning_hours: number
          user_id: string
        }
        Insert: {
          assessment_score?: number | null
          business_name?: string | null
          certificate_number: string
          certificate_type: string
          course_id: string
          course_title: string
          created_at?: string
          credential_level: string
          id?: string
          issued_at?: string
          learner_name: string
          learning_hours?: number
          user_id: string
        }
        Update: {
          assessment_score?: number | null
          business_name?: string | null
          certificate_number?: string
          certificate_type?: string
          course_id?: string
          course_title?: string
          created_at?: string
          credential_level?: string
          id?: string
          issued_at?: string
          learner_name?: string
          learning_hours?: number
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "certificates_course_id_fkey"
            columns: ["course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      course_progress: {
        Row: {
          completed_at: string
          course_id: string
          id: string
          lesson_index: number
          user_id: string
        }
        Insert: {
          completed_at?: string
          course_id: string
          id?: string
          lesson_index: number
          user_id: string
        }
        Update: {
          completed_at?: string
          course_id?: string
          id?: string
          lesson_index?: number
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "course_progress_course_id_fkey"
            columns: ["course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      course_recommendations: {
        Row: {
          course_id: string
          created_at: string
          domain_code: string
          id: string
          max_score: number
          min_score: number
          priority: number
        }
        Insert: {
          course_id: string
          created_at?: string
          domain_code: string
          id?: string
          max_score?: number
          min_score?: number
          priority?: number
        }
        Update: {
          course_id?: string
          created_at?: string
          domain_code?: string
          id?: string
          max_score?: number
          min_score?: number
          priority?: number
        }
        Relationships: [
          {
            foreignKeyName: "course_recommendations_course_id_fkey"
            columns: ["course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      courses: {
        Row: {
          category_slug: string
          certificate_type: string
          created_at: string
          credential_level: string
          description: string
          domain_code: string
          duration_minutes: number
          duration_weeks: number
          group_code: string
          group_name: string
          id: string
          is_premium: boolean
          learning_hours: number
          learning_outcomes: string[]
          lessons: Json
          level: string
          prerequisite_course_id: string | null
          price_kes: number
          slug: string
          sort_order: number
          summary: string
          title: string
        }
        Insert: {
          category_slug: string
          certificate_type?: string
          created_at?: string
          credential_level?: string
          description: string
          domain_code?: string
          duration_minutes?: number
          duration_weeks?: number
          group_code?: string
          group_name?: string
          id?: string
          is_premium?: boolean
          learning_hours?: number
          learning_outcomes?: string[]
          lessons?: Json
          level?: string
          prerequisite_course_id?: string | null
          price_kes?: number
          slug: string
          sort_order?: number
          summary: string
          title: string
        }
        Update: {
          category_slug?: string
          certificate_type?: string
          created_at?: string
          credential_level?: string
          description?: string
          domain_code?: string
          duration_minutes?: number
          duration_weeks?: number
          group_code?: string
          group_name?: string
          id?: string
          is_premium?: boolean
          learning_hours?: number
          learning_outcomes?: string[]
          lessons?: Json
          level?: string
          prerequisite_course_id?: string | null
          price_kes?: number
          slug?: string
          sort_order?: number
          summary?: string
          title?: string
        }
        Relationships: [
          {
            foreignKeyName: "courses_prerequisite_course_id_fkey"
            columns: ["prerequisite_course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      enrollments: {
        Row: {
          course_id: string
          created_at: string
          id: string
          user_id: string
        }
        Insert: {
          course_id: string
          created_at?: string
          id?: string
          user_id: string
        }
        Update: {
          course_id?: string
          created_at?: string
          id?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "enrollments_course_id_fkey"
            columns: ["course_id"]
            isOneToOne: false
            referencedRelation: "courses"
            referencedColumns: ["id"]
          },
        ]
      }
      plan_upgrade_requests: {
        Row: {
          amount_kes: number
          contact_email: string | null
          contact_phone: string | null
          created_at: string
          id: string
          membership_category: string
          notes: string | null
          payment_method: string
          payment_reference: string
          plan: string
          status: string
          updated_at: string
          user_id: string
        }
        Insert: {
          amount_kes?: number
          contact_email?: string | null
          contact_phone?: string | null
          created_at?: string
          id?: string
          membership_category: string
          notes?: string | null
          payment_method: string
          payment_reference: string
          plan: string
          status?: string
          updated_at?: string
          user_id: string
        }
        Update: {
          amount_kes?: number
          contact_email?: string | null
          contact_phone?: string | null
          created_at?: string
          id?: string
          membership_category?: string
          notes?: string | null
          payment_method?: string
          payment_reference?: string
          plan?: string
          status?: string
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      profiles: {
        Row: {
          avatar_url: string | null
          business_name: string | null
          business_size: string | null
          county: string | null
          created_at: string
          full_name: string | null
          id: string
          member_reference: string | null
          membership_category: string
          plan_activated_at: string | null
          plan_tier: string
          sector: string | null
          team_id: string | null
          updated_at: string
        }
        Insert: {
          avatar_url?: string | null
          business_name?: string | null
          business_size?: string | null
          county?: string | null
          created_at?: string
          full_name?: string | null
          id: string
          member_reference?: string | null
          membership_category?: string
          plan_activated_at?: string | null
          plan_tier?: string
          sector?: string | null
          team_id?: string | null
          updated_at?: string
        }
        Update: {
          avatar_url?: string | null
          business_name?: string | null
          business_size?: string | null
          county?: string | null
          created_at?: string
          full_name?: string | null
          id?: string
          member_reference?: string | null
          membership_category?: string
          plan_activated_at?: string | null
          plan_tier?: string
          sector?: string | null
          team_id?: string | null
          updated_at?: string
        }
        Relationships: []
      }
      team_members: {
        Row: {
          created_at: string
          id: string
          invite_email: string | null
          team_id: string
          user_id: string | null
        }
        Insert: {
          created_at?: string
          id?: string
          invite_email?: string | null
          team_id: string
          user_id?: string | null
        }
        Update: {
          created_at?: string
          id?: string
          invite_email?: string | null
          team_id?: string
          user_id?: string | null
        }
        Relationships: [
          {
            foreignKeyName: "team_members_team_id_fkey"
            columns: ["team_id"]
            isOneToOne: false
            referencedRelation: "teams"
            referencedColumns: ["id"]
          },
        ]
      }
      teams: {
        Row: {
          created_at: string
          id: string
          name: string
          owner_id: string
          plan_tier: string
          seat_limit: number
        }
        Insert: {
          created_at?: string
          id?: string
          name: string
          owner_id: string
          plan_tier?: string
          seat_limit?: number
        }
        Update: {
          created_at?: string
          id?: string
          name?: string
          owner_id?: string
          plan_tier?: string
          seat_limit?: number
        }
        Relationships: []
      }
    }
    Views: {
      [_ in never]: never
    }
    Functions: {
      verify_certificate: {
        Args: { _number: string }
        Returns: {
          assessment_score: number
          business_name: string
          certificate_number: string
          certificate_type: string
          course_title: string
          credential_level: string
          issued_at: string
          learner_name: string
          learning_hours: number
        }[]
      }
    }
    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
