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: "13.0.4"
  }
  public: {
    Tables: {
      admin_chat_messages: {
        Row: {
          actions: Json | null
          content: string
          created_at: string
          id: string
          role: string
          timestamp: string
          user_id: string
        }
        Insert: {
          actions?: Json | null
          content: string
          created_at?: string
          id?: string
          role: string
          timestamp?: string
          user_id: string
        }
        Update: {
          actions?: Json | null
          content?: string
          created_at?: string
          id?: string
          role?: string
          timestamp?: string
          user_id?: string
        }
        Relationships: []
      }
      admin_profiles: {
        Row: {
          created_at: string
          department: string | null
          id: string
          is_active: boolean | null
          last_conversation_at: string | null
          last_login_at: string | null
          last_login_ip: string | null
          login_count: number | null
          notes: string | null
          permissions: Json | null
          position: string | null
          total_conversations: number | null
          total_messages: number | null
          updated_at: string
          user_id: string
        }
        Insert: {
          created_at?: string
          department?: string | null
          id?: string
          is_active?: boolean | null
          last_conversation_at?: string | null
          last_login_at?: string | null
          last_login_ip?: string | null
          login_count?: number | null
          notes?: string | null
          permissions?: Json | null
          position?: string | null
          total_conversations?: number | null
          total_messages?: number | null
          updated_at?: string
          user_id: string
        }
        Update: {
          created_at?: string
          department?: string | null
          id?: string
          is_active?: boolean | null
          last_conversation_at?: string | null
          last_login_at?: string | null
          last_login_ip?: string | null
          login_count?: number | null
          notes?: string | null
          permissions?: Json | null
          position?: string | null
          total_conversations?: number | null
          total_messages?: number | null
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      after_sales_requests: {
        Row: {
          admin_notes: string | null
          created_at: string
          description: string
          id: string
          images: string[] | null
          order_id: string
          processed_at: string | null
          processed_by: string | null
          product_id: string
          reason: string
          refund_amount: number | null
          status: string
          tracking_number: string | null
          type: string
          updated_at: string
          user_id: string
        }
        Insert: {
          admin_notes?: string | null
          created_at?: string
          description: string
          id?: string
          images?: string[] | null
          order_id: string
          processed_at?: string | null
          processed_by?: string | null
          product_id: string
          reason: string
          refund_amount?: number | null
          status?: string
          tracking_number?: string | null
          type: string
          updated_at?: string
          user_id: string
        }
        Update: {
          admin_notes?: string | null
          created_at?: string
          description?: string
          id?: string
          images?: string[] | null
          order_id?: string
          processed_at?: string | null
          processed_by?: string | null
          product_id?: string
          reason?: string
          refund_amount?: number | null
          status?: string
          tracking_number?: string | null
          type?: string
          updated_at?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "after_sales_requests_order_id_fkey"
            columns: ["order_id"]
            isOneToOne: false
            referencedRelation: "orders"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "after_sales_requests_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "after_sales_requests_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products_search_view"
            referencedColumns: ["id"]
          },
        ]
      }
      agent_context: {
        Row: {
          conversation_context: Json
          created_at: string
          domain_context: Json
          id: string
          selected_items: Json
          session_id: string
          updated_at: string
          user_id: string
          version: number
        }
        Insert: {
          conversation_context?: Json
          created_at?: string
          domain_context?: Json
          id?: string
          selected_items?: Json
          session_id: string
          updated_at?: string
          user_id: string
          version?: number
        }
        Update: {
          conversation_context?: Json
          created_at?: string
          domain_context?: Json
          id?: string
          selected_items?: Json
          session_id?: string
          updated_at?: string
          user_id?: string
          version?: number
        }
        Relationships: []
      }
      agent_roles: {
        Row: {
          allowed_actions: string[] | null
          capabilities: string[] | null
          color: string | null
          created_at: string
          description: string
          display_order: number | null
          icon: string | null
          id: string
          is_active: boolean | null
          name: string
          role_id: string
          updated_at: string
        }
        Insert: {
          allowed_actions?: string[] | null
          capabilities?: string[] | null
          color?: string | null
          created_at?: string
          description: string
          display_order?: number | null
          icon?: string | null
          id?: string
          is_active?: boolean | null
          name: string
          role_id: string
          updated_at?: string
        }
        Update: {
          allowed_actions?: string[] | null
          capabilities?: string[] | null
          color?: string | null
          created_at?: string
          description?: string
          display_order?: number | null
          icon?: string | null
          id?: string
          is_active?: boolean | null
          name?: string
          role_id?: string
          updated_at?: string
        }
        Relationships: []
      }
      agent_settings: {
        Row: {
          agent_type: string
          auto_execute_enabled: boolean
          created_at: string
          id: string
          is_active: boolean
          max_auto_amount: number
          monthly_goals: Json
          notify_on_approvals: boolean
          notify_on_errors: boolean
          notify_on_insights: boolean
          requires_approval_types: string[]
          response_style: string
          tone: string
          updated_at: string
        }
        Insert: {
          agent_type: string
          auto_execute_enabled?: boolean
          created_at?: string
          id?: string
          is_active?: boolean
          max_auto_amount?: number
          monthly_goals?: Json
          notify_on_approvals?: boolean
          notify_on_errors?: boolean
          notify_on_insights?: boolean
          requires_approval_types?: string[]
          response_style?: string
          tone?: string
          updated_at?: string
        }
        Update: {
          agent_type?: string
          auto_execute_enabled?: boolean
          created_at?: string
          id?: string
          is_active?: boolean
          max_auto_amount?: number
          monthly_goals?: Json
          notify_on_approvals?: boolean
          notify_on_errors?: boolean
          notify_on_insights?: boolean
          requires_approval_types?: string[]
          response_style?: string
          tone?: string
          updated_at?: string
        }
        Relationships: []
      }
      agent_test_results: {
        Row: {
          agent_type: string
          created_at: string
          id: string
          issues: string[] | null
          passed: boolean
          response_summary: Json | null
          trace_id: string
          user_message: string
        }
        Insert: {
          agent_type?: string
          created_at?: string
          id?: string
          issues?: string[] | null
          passed?: boolean
          response_summary?: Json | null
          trace_id: string
          user_message: string
        }
        Update: {
          agent_type?: string
          created_at?: string
          id?: string
          issues?: string[] | null
          passed?: boolean
          response_summary?: Json | null
          trace_id?: string
          user_message?: string
        }
        Relationships: []
      }
      ai_image_style_presets: {
        Row: {
          created_at: string
          description: string | null
          enabled: boolean
          id: string
          is_builtin: boolean
          key: string
          label: string
          prompt: string
          sort_order: number
          updated_at: string
        }
        Insert: {
          created_at?: string
          description?: string | null
          enabled?: boolean
          id?: string
          is_builtin?: boolean
          key: string
          label: string
          prompt: string
          sort_order?: number
          updated_at?: string
        }
        Update: {
          created_at?: string
          description?: string | null
          enabled?: boolean
          id?: string
          is_builtin?: boolean
          key?: string
          label?: string
          prompt?: string
          sort_order?: number
          updated_at?: string
        }
        Relationships: []
      }
      ai_provider_configs: {
        Row: {
          category: string
          created_at: string
          description: string | null
          display_order: number
          enabled: boolean
          extra: Json
          id: string
          model: string
          provider: string
          purpose: string
          updated_at: string
          updated_by: string | null
        }
        Insert: {
          category?: string
          created_at?: string
          description?: string | null
          display_order?: number
          enabled?: boolean
          extra?: Json
          id?: string
          model: string
          provider?: string
          purpose: string
          updated_at?: string
          updated_by?: string | null
        }
        Update: {
          category?: string
          created_at?: string
          description?: string | null
          display_order?: number
          enabled?: boolean
          extra?: Json
          id?: string
          model?: string
          provider?: string
          purpose?: string
          updated_at?: string
          updated_by?: string | null
        }
        Relationships: []
      }
      ai_read_log: {
        Row: {
          actor_id: string | null
          ai_tool: string
          guide_id: string
          guide_sha256: string | null
          guide_version: string
          id: string
          read_at: string
          session_id: string | null
        }
        Insert: {
          actor_id?: string | null
          ai_tool: string
          guide_id: string
          guide_sha256?: string | null
          guide_version: string
          id?: string
          read_at?: string
          session_id?: string | null
        }
        Update: {
          actor_id?: string | null
          ai_tool?: string
          guide_id?: string
          guide_sha256?: string | null
          guide_version?: string
          id?: string
          read_at?: string
          session_id?: string | null
        }
        Relationships: [
          {
            foreignKeyName: "ai_read_log_guide_id_fkey"
            columns: ["guide_id"]
            isOneToOne: false
            referencedRelation: "system_guide"
            referencedColumns: ["id"]
          },
        ]
      }
      api_registry: {
        Row: {
          auth_required: boolean | null
          category: string
          created_at: string
          description: string
          display_order: number | null
          endpoint: string
          examples: Json | null
          id: string
          is_active: boolean | null
          method: string
          name: string
          parameters: Json | null
          response_schema: Json | null
          tags: string[] | null
          updated_at: string
        }
        Insert: {
          auth_required?: boolean | null
          category: string
          created_at?: string
          description: string
          display_order?: number | null
          endpoint: string
          examples?: Json | null
          id?: string
          is_active?: boolean | null
          method?: string
          name: string
          parameters?: Json | null
          response_schema?: Json | null
          tags?: string[] | null
          updated_at?: string
        }
        Update: {
          auth_required?: boolean | null
          category?: string
          created_at?: string
          description?: string
          display_order?: number | null
          endpoint?: string
          examples?: Json | null
          id?: string
          is_active?: boolean | null
          method?: string
          name?: string
          parameters?: Json | null
          response_schema?: Json | null
          tags?: string[] | null
          updated_at?: string
        }
        Relationships: []
      }
      balance_transactions: {
        Row: {
          amount: number
          balance_after: number
          balance_before: number
          created_at: string
          description: string | null
          id: string
          order_id: string | null
          recharge_plan_id: string | null
          type: string
          user_id: string
        }
        Insert: {
          amount: number
          balance_after: number
          balance_before: number
          created_at?: string
          description?: string | null
          id?: string
          order_id?: string | null
          recharge_plan_id?: string | null
          type: string
          user_id: string
        }
        Update: {
          amount?: number
          balance_after?: number
          balance_before?: number
          created_at?: string
          description?: string | null
          id?: string
          order_id?: string | null
          recharge_plan_id?: string | null
          type?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "balance_transactions_order_id_fkey"
            columns: ["order_id"]
            isOneToOne: false
            referencedRelation: "orders"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "balance_transactions_recharge_plan_id_fkey"
            columns: ["recharge_plan_id"]
            isOneToOne: false
            referencedRelation: "recharge_plans"
            referencedColumns: ["id"]
          },
        ]
      }
      banners: {
        Row: {
          button_text: string | null
          created_at: string
          display_order: number
          id: string
          image_url: string | null
          is_active: boolean
          link_url: string | null
          subtitle: string | null
          title: string
          updated_at: string
        }
        Insert: {
          button_text?: string | null
          created_at?: string
          display_order?: number
          id?: string
          image_url?: string | null
          is_active?: boolean
          link_url?: string | null
          subtitle?: string | null
          title: string
          updated_at?: string
        }
        Update: {
          button_text?: string | null
          created_at?: string
          display_order?: number
          id?: string
          image_url?: string | null
          is_active?: boolean
          link_url?: string | null
          subtitle?: string | null
          title?: string
          updated_at?: string
        }
        Relationships: []
      }
      brands: {
        Row: {
          aliases: string[] | null
          created_at: string
          description: string | null
          display_order: number | null
          id: string
          is_active: boolean
          logo_url: string | null
          name: string
          updated_at: string
        }
        Insert: {
          aliases?: string[] | null
          created_at?: string
          description?: string | null
          display_order?: number | null
          id?: string
          is_active?: boolean
          logo_url?: string | null
          name: string
          updated_at?: string
        }
        Update: {
          aliases?: string[] | null
          created_at?: string
          description?: string | null
          display_order?: number | null
          id?: string
          is_active?: boolean
          logo_url?: string | null
          name?: string
          updated_at?: string
        }
        Relationships: []
      }
      business_alerts: {
        Row: {
          alert_type: string
          category: Database["public"]["Enums"]["alert_category"]
          created_at: string
          data: Json | null
          description: string
          expires_at: string | null
          id: string
          is_dismissed: boolean
          is_read: boolean
          read_at: string | null
          severity: Database["public"]["Enums"]["alert_severity"]
          target_agent: string
          title: string
        }
        Insert: {
          alert_type: string
          category: Database["public"]["Enums"]["alert_category"]
          created_at?: string
          data?: Json | null
          description: string
          expires_at?: string | null
          id?: string
          is_dismissed?: boolean
          is_read?: boolean
          read_at?: string | null
          severity?: Database["public"]["Enums"]["alert_severity"]
          target_agent?: string
          title: string
        }
        Update: {
          alert_type?: string
          category?: Database["public"]["Enums"]["alert_category"]
          created_at?: string
          data?: Json | null
          description?: string
          expires_at?: string | null
          id?: string
          is_dismissed?: boolean
          is_read?: boolean
          read_at?: string | null
          severity?: Database["public"]["Enums"]["alert_severity"]
          target_agent?: string
          title?: string
        }
        Relationships: []
      }
      categories: {
        Row: {
          created_at: string
          description: string | null
          display_order: number | null
          id: string
          is_active: boolean
          name: string
          parent_id: string | null
          updated_at: string
        }
        Insert: {
          created_at?: string
          description?: string | null
          display_order?: number | null
          id?: string
          is_active?: boolean
          name: string
          parent_id?: string | null
          updated_at?: string
        }
        Update: {
          created_at?: string
          description?: string | null
          display_order?: number | null
          id?: string
          is_active?: boolean
          name?: string
          parent_id?: string | null
          updated_at?: string
        }
        Relationships: [
          {
            foreignKeyName: "categories_parent_id_fkey"
            columns: ["parent_id"]
            isOneToOne: false
            referencedRelation: "categories"
            referencedColumns: ["id"]
          },
        ]
      }
      category_brands: {
        Row: {
          brand_id: string
          category_id: string
          created_at: string
          id: string
        }
        Insert: {
          brand_id: string
          category_id: string
          created_at?: string
          id?: string
        }
        Update: {
          brand_id?: string
          category_id?: string
          created_at?: string
          id?: string
        }
        Relationships: [
          {
            foreignKeyName: "category_brands_brand_id_fkey"
            columns: ["brand_id"]
            isOneToOne: false
            referencedRelation: "brands"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "category_brands_category_id_fkey"
            columns: ["category_id"]
            isOneToOne: false
            referencedRelation: "categories"
            referencedColumns: ["id"]
          },
        ]
      }
      context_changes: {
        Row: {
          agent_type: string
          changes: Json
          context_id: string
          correlation_id: string
          created_at: string
          id: string
          idempotency_key: string
          version_after: number
          version_before: number
        }
        Insert: {
          agent_type: string
          changes?: Json
          context_id: string
          correlation_id: string
          created_at?: string
          id?: string
          idempotency_key: string
          version_after: number
          version_before: number
        }
        Update: {
          agent_type?: string
          changes?: Json
          context_id?: string
          correlation_id?: string
          created_at?: string
          id?: string
          idempotency_key?: string
          version_after?: number
          version_before?: number
        }
        Relationships: [
          {
            foreignKeyName: "context_changes_context_id_fkey"
            columns: ["context_id"]
            isOneToOne: false
            referencedRelation: "agent_context"
            referencedColumns: ["id"]
          },
        ]
      }
      conversations: {
        Row: {
          created_at: string
          dify_conversation_id: string | null
          id: string
          title: string
          updated_at: string
          user_id: string
        }
        Insert: {
          created_at?: string
          dify_conversation_id?: string | null
          id?: string
          title?: string
          updated_at?: string
          user_id: string
        }
        Update: {
          created_at?: string
          dify_conversation_id?: string | null
          id?: string
          title?: string
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      coupons: {
        Row: {
          code: string
          created_at: string | null
          description: string | null
          discount_value: number
          end_date: string
          id: string
          max_discount_amount: number | null
          min_purchase_amount: number | null
          name: string
          per_user_limit: number | null
          scope: string
          scope_ids: string[] | null
          start_date: string
          status: string
          total_quantity: number
          type: string
          updated_at: string | null
          used_quantity: number | null
        }
        Insert: {
          code: string
          created_at?: string | null
          description?: string | null
          discount_value: number
          end_date: string
          id?: string
          max_discount_amount?: number | null
          min_purchase_amount?: number | null
          name: string
          per_user_limit?: number | null
          scope?: string
          scope_ids?: string[] | null
          start_date: string
          status?: string
          total_quantity: number
          type: string
          updated_at?: string | null
          used_quantity?: number | null
        }
        Update: {
          code?: string
          created_at?: string | null
          description?: string | null
          discount_value?: number
          end_date?: string
          id?: string
          max_discount_amount?: number | null
          min_purchase_amount?: number | null
          name?: string
          per_user_limit?: number | null
          scope?: string
          scope_ids?: string[] | null
          start_date?: string
          status?: string
          total_quantity?: number
          type?: string
          updated_at?: string | null
          used_quantity?: number | null
        }
        Relationships: []
      }
      cross_store_promotion_stores: {
        Row: {
          contribution_ratio: number | null
          created_at: string
          id: string
          joined_at: string | null
          promotion_id: string
          sales_amount: number | null
          sales_count: number | null
          status: string | null
          store_name: string
          store_type: string | null
        }
        Insert: {
          contribution_ratio?: number | null
          created_at?: string
          id?: string
          joined_at?: string | null
          promotion_id: string
          sales_amount?: number | null
          sales_count?: number | null
          status?: string | null
          store_name: string
          store_type?: string | null
        }
        Update: {
          contribution_ratio?: number | null
          created_at?: string
          id?: string
          joined_at?: string | null
          promotion_id?: string
          sales_amount?: number | null
          sales_count?: number | null
          status?: string | null
          store_name?: string
          store_type?: string | null
        }
        Relationships: [
          {
            foreignKeyName: "cross_store_promotion_stores_promotion_id_fkey"
            columns: ["promotion_id"]
            isOneToOne: false
            referencedRelation: "cross_store_promotions"
            referencedColumns: ["id"]
          },
        ]
      }
      cross_store_promotions: {
        Row: {
          ai_strategy: string | null
          config: Json
          created_at: string
          created_by: string
          created_by_user_id: string | null
          current_participants: number | null
          description: string | null
          end_date: string
          id: string
          max_participants: number | null
          name: string
          review_notes: string | null
          reviewed_at: string | null
          reviewed_by: string | null
          start_date: string
          status: string
          store_ids: string[]
          total_budget: number | null
          type: string
          updated_at: string
          used_budget: number | null
        }
        Insert: {
          ai_strategy?: string | null
          config?: Json
          created_at?: string
          created_by?: string
          created_by_user_id?: string | null
          current_participants?: number | null
          description?: string | null
          end_date: string
          id?: string
          max_participants?: number | null
          name: string
          review_notes?: string | null
          reviewed_at?: string | null
          reviewed_by?: string | null
          start_date: string
          status?: string
          store_ids?: string[]
          total_budget?: number | null
          type?: string
          updated_at?: string
          used_budget?: number | null
        }
        Update: {
          ai_strategy?: string | null
          config?: Json
          created_at?: string
          created_by?: string
          created_by_user_id?: string | null
          current_participants?: number | null
          description?: string | null
          end_date?: string
          id?: string
          max_participants?: number | null
          name?: string
          review_notes?: string | null
          reviewed_at?: string | null
          reviewed_by?: string | null
          start_date?: string
          status?: string
          store_ids?: string[]
          total_budget?: number | null
          type?: string
          updated_at?: string
          used_budget?: number | null
        }
        Relationships: []
      }
      error_logs: {
        Row: {
          component_stack: string | null
          context: Json | null
          created_at: string
          id: string
          message: string
          severity: string
          stack: string | null
          url: string | null
          user_agent: string | null
          user_id: string | null
        }
        Insert: {
          component_stack?: string | null
          context?: Json | null
          created_at?: string
          id?: string
          message: string
          severity?: string
          stack?: string | null
          url?: string | null
          user_agent?: string | null
          user_id?: string | null
        }
        Update: {
          component_stack?: string | null
          context?: Json | null
          created_at?: string
          id?: string
          message?: string
          severity?: string
          stack?: string | null
          url?: string | null
          user_agent?: string | null
          user_id?: string | null
        }
        Relationships: []
      }
      flash_sales: {
        Row: {
          ai_strategy: string | null
          created_at: string
          created_by: string
          description: string | null
          end_time: string
          flash_price: number
          id: string
          name: string
          original_price: number
          per_user_limit: number | null
          product_id: string
          sold_count: number
          start_time: string
          status: string
          stock_limit: number
          type: string
          updated_at: string
        }
        Insert: {
          ai_strategy?: string | null
          created_at?: string
          created_by?: string
          description?: string | null
          end_time: string
          flash_price: number
          id?: string
          name: string
          original_price: number
          per_user_limit?: number | null
          product_id: string
          sold_count?: number
          start_time: string
          status?: string
          stock_limit?: number
          type?: string
          updated_at?: string
        }
        Update: {
          ai_strategy?: string | null
          created_at?: string
          created_by?: string
          description?: string | null
          end_time?: string
          flash_price?: number
          id?: string
          name?: string
          original_price?: number
          per_user_limit?: number | null
          product_id?: string
          sold_count?: number
          start_time?: string
          status?: string
          stock_limit?: number
          type?: string
          updated_at?: string
        }
        Relationships: [
          {
            foreignKeyName: "flash_sales_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "flash_sales_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products_search_view"
            referencedColumns: ["id"]
          },
        ]
      }
      genui_components: {
        Row: {
          category: string | null
          component_type: string
          created_at: string
          description: string
          display_order: number | null
          example: Json | null
          id: string
          is_active: boolean | null
          name: string
          props_schema: Json
          updated_at: string
        }
        Insert: {
          category?: string | null
          component_type: string
          created_at?: string
          description: string
          display_order?: number | null
          example?: Json | null
          id?: string
          is_active?: boolean | null
          name: string
          props_schema?: Json
          updated_at?: string
        }
        Update: {
          category?: string | null
          component_type?: string
          created_at?: string
          description?: string
          display_order?: number | null
          example?: Json | null
          id?: string
          is_active?: boolean | null
          name?: string
          props_schema?: Json
          updated_at?: string
        }
        Relationships: []
      }
      goals: {
        Row: {
          agent_type: string
          assigned_by: string | null
          assigned_to: string | null
          created_at: string
          created_by: string | null
          current_value: number
          deadline: string
          description: string | null
          id: string
          priority: string
          status: string
          target_value: number
          title: string
          unit: string
          updated_at: string
        }
        Insert: {
          agent_type: string
          assigned_by?: string | null
          assigned_to?: string | null
          created_at?: string
          created_by?: string | null
          current_value?: number
          deadline: string
          description?: string | null
          id?: string
          priority?: string
          status?: string
          target_value: number
          title: string
          unit?: string
          updated_at?: string
        }
        Update: {
          agent_type?: string
          assigned_by?: string | null
          assigned_to?: string | null
          created_at?: string
          created_by?: string | null
          current_value?: number
          deadline?: string
          description?: string | null
          id?: string
          priority?: string
          status?: string
          target_value?: number
          title?: string
          unit?: string
          updated_at?: string
        }
        Relationships: []
      }
      group_buy_activities: {
        Row: {
          ai_strategy: string | null
          created_at: string
          created_by: string
          description: string | null
          duration_hours: number
          end_date: string
          group_price: number
          id: string
          max_group_size: number
          min_group_size: number
          name: string
          original_price: number
          product_id: string
          sold_count: number
          start_date: string
          status: string
          stock_limit: number | null
          updated_at: string
        }
        Insert: {
          ai_strategy?: string | null
          created_at?: string
          created_by?: string
          description?: string | null
          duration_hours?: number
          end_date: string
          group_price: number
          id?: string
          max_group_size?: number
          min_group_size?: number
          name: string
          original_price: number
          product_id: string
          sold_count?: number
          start_date: string
          status?: string
          stock_limit?: number | null
          updated_at?: string
        }
        Update: {
          ai_strategy?: string | null
          created_at?: string
          created_by?: string
          description?: string | null
          duration_hours?: number
          end_date?: string
          group_price?: number
          id?: string
          max_group_size?: number
          min_group_size?: number
          name?: string
          original_price?: number
          product_id?: string
          sold_count?: number
          start_date?: string
          status?: string
          stock_limit?: number | null
          updated_at?: string
        }
        Relationships: [
          {
            foreignKeyName: "group_buy_activities_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "group_buy_activities_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products_search_view"
            referencedColumns: ["id"]
          },
        ]
      }
      group_buy_members: {
        Row: {
          group_order_id: string
          id: string
          joined_at: string
          order_id: string | null
          user_id: string
        }
        Insert: {
          group_order_id: string
          id?: string
          joined_at?: string
          order_id?: string | null
          user_id: string
        }
        Update: {
          group_order_id?: string
          id?: string
          joined_at?: string
          order_id?: string | null
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "group_buy_members_group_order_id_fkey"
            columns: ["group_order_id"]
            isOneToOne: false
            referencedRelation: "group_buy_orders"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "group_buy_members_order_id_fkey"
            columns: ["order_id"]
            isOneToOne: false
            referencedRelation: "orders"
            referencedColumns: ["id"]
          },
        ]
      }
      group_buy_orders: {
        Row: {
          activity_id: string
          completed_at: string | null
          created_at: string
          current_size: number
          expire_at: string
          id: string
          leader_user_id: string
          status: string
          updated_at: string
        }
        Insert: {
          activity_id: string
          completed_at?: string | null
          created_at?: string
          current_size?: number
          expire_at: string
          id?: string
          leader_user_id: string
          status?: string
          updated_at?: string
        }
        Update: {
          activity_id?: string
          completed_at?: string | null
          created_at?: string
          current_size?: number
          expire_at?: string
          id?: string
          leader_user_id?: string
          status?: string
          updated_at?: string
        }
        Relationships: [
          {
            foreignKeyName: "group_buy_orders_activity_id_fkey"
            columns: ["activity_id"]
            isOneToOne: false
            referencedRelation: "group_buy_activities"
            referencedColumns: ["id"]
          },
        ]
      }
      knowledge_base: {
        Row: {
          category: string | null
          content: string
          created_at: string
          embedding: string | null
          id: string
          is_active: boolean
          metadata: Json | null
          source_path: string | null
          source_type: string
          tags: string[] | null
          title: string
          updated_at: string
        }
        Insert: {
          category?: string | null
          content: string
          created_at?: string
          embedding?: string | null
          id?: string
          is_active?: boolean
          metadata?: Json | null
          source_path?: string | null
          source_type?: string
          tags?: string[] | null
          title: string
          updated_at?: string
        }
        Update: {
          category?: string | null
          content?: string
          created_at?: string
          embedding?: string | null
          id?: string
          is_active?: boolean
          metadata?: Json | null
          source_path?: string | null
          source_type?: string
          tags?: string[] | null
          title?: string
          updated_at?: string
        }
        Relationships: []
      }
      marketing_campaigns: {
        Row: {
          ai_strategy: string | null
          config: Json | null
          created_at: string
          created_by: string
          created_by_user_id: string | null
          description: string | null
          end_date: string
          id: string
          name: string
          related_coupon_id: string | null
          review_notes: string | null
          reviewed_at: string | null
          reviewed_by: string | null
          start_date: string
          status: string
          type: string
          updated_at: string
        }
        Insert: {
          ai_strategy?: string | null
          config?: Json | null
          created_at?: string
          created_by?: string
          created_by_user_id?: string | null
          description?: string | null
          end_date: string
          id?: string
          name: string
          related_coupon_id?: string | null
          review_notes?: string | null
          reviewed_at?: string | null
          reviewed_by?: string | null
          start_date: string
          status?: string
          type?: string
          updated_at?: string
        }
        Update: {
          ai_strategy?: string | null
          config?: Json | null
          created_at?: string
          created_by?: string
          created_by_user_id?: string | null
          description?: string | null
          end_date?: string
          id?: string
          name?: string
          related_coupon_id?: string | null
          review_notes?: string | null
          reviewed_at?: string | null
          reviewed_by?: string | null
          start_date?: string
          status?: string
          type?: string
          updated_at?: string
        }
        Relationships: [
          {
            foreignKeyName: "marketing_campaigns_related_coupon_id_fkey"
            columns: ["related_coupon_id"]
            isOneToOne: false
            referencedRelation: "coupons"
            referencedColumns: ["id"]
          },
        ]
      }
      messages: {
        Row: {
          content: string
          conversation_id: string
          created_at: string
          id: string
          message_type: string
          metadata: Json | null
          sender_type: string
          user_id: string
        }
        Insert: {
          content: string
          conversation_id: string
          created_at?: string
          id?: string
          message_type?: string
          metadata?: Json | null
          sender_type?: string
          user_id: string
        }
        Update: {
          content?: string
          conversation_id?: string
          created_at?: string
          id?: string
          message_type?: string
          metadata?: Json | null
          sender_type?: string
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "messages_conversation_id_fkey"
            columns: ["conversation_id"]
            isOneToOne: false
            referencedRelation: "conversations"
            referencedColumns: ["id"]
          },
        ]
      }
      order_items: {
        Row: {
          created_at: string
          id: string
          order_id: string
          product_id: string
          quantity: number
          unit_price: number
        }
        Insert: {
          created_at?: string
          id?: string
          order_id: string
          product_id: string
          quantity: number
          unit_price: number
        }
        Update: {
          created_at?: string
          id?: string
          order_id?: string
          product_id?: string
          quantity?: number
          unit_price?: number
        }
        Relationships: [
          {
            foreignKeyName: "order_items_order_id_fkey"
            columns: ["order_id"]
            isOneToOne: false
            referencedRelation: "orders"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "order_items_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "order_items_product_id_fkey"
            columns: ["product_id"]
            isOneToOne: false
            referencedRelation: "products_search_view"
            referencedColumns: ["id"]
          },
        ]
      }
      orders: {
        Row: {
          created_at: string
          id: string
          notes: string | null
          order_number: string
          shipped_at: string | null
          shipping_address: string | null
          status: string
          total_amount: number
          tracking_number: string | null
          updated_at: string
          user_id: string
        }
        Insert: {
          created_at?: string
          id?: string
          notes?: string | null
          order_number: string
          shipped_at?: string | null
          shipping_address?: string | null
          status?: string
          total_amount: number
          tracking_number?: string | null
          updated_at?: string
          user_id: string
        }
        Update: {
          created_at?: string
          id?: string
          notes?: string | null
          order_number?: string
          shipped_at?: string | null
          shipping_address?: string | null
          status?: string
          total_amount?: number
          tracking_number?: string | null
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      payment_gifts: {
        Row: {
          ai_strategy: string | null
          created_at: string
          created_by: string
          description: string | null
          end_date: string
          gift_type: string
          gift_value: Json
          id: string
          min_payment_amount: number
          name: string
          probability: number
          start_date: string
          status: string
          total_quantity: number | null
          updated_at: string
          used_quantity: number
        }
        Insert: {
          ai_strategy?: string | null
          created_at?: string
          created_by?: string
          description?: string | null
          end_date: string
          gift_type?: string
          gift_value?: Json
          id?: string
          min_payment_amount?: number
          name: string
          probability?: number
          start_date: string
          status?: string
          total_quantity?: number | null
          updated_at?: string
          used_quantity?: number
        }
        Update: {
          ai_strategy?: string | null
          created_at?: string
          created_by?: string
          description?: string | null
          end_date?: string
          gift_type?: string
          gift_value?: Json
          id?: string
          min_payment_amount?: number
          name?: string
          probability?: number
          start_date?: string
          status?: string
          total_quantity?: number | null
          updated_at?: string
          used_quantity?: number
        }
        Relationships: []
      }
      perf_logs: {
        Row: {
          context: Json | null
          created_at: string
          duration_ms: number
          id: string
          metric_name: string
          metric_type: string
          url: string | null
          user_id: string | null
        }
        Insert: {
          context?: Json | null
          created_at?: string
          duration_ms: number
          id?: string
          metric_name: string
          metric_type: string
          url?: string | null
          user_id?: string | null
        }
        Update: {
          context?: Json | null
          created_at?: string
          duration_ms?: number
          id?: string
          metric_name?: string
          metric_type?: string
          url?: string | null
          user_id?: string | null
        }
        Relationships: []
      }
      products: {
        Row: {
          battery_capacity: string | null
          battery_mah: number | null
          brand: string | null
          category: string | null
          charging_power: number | null
          comment_tags: string | null
          core_processor: string | null
          created_at: string
          description: string | null
          front_camera_pixels: number | null
          id: string
          image_url: string | null
          images: string[] | null
          is_active: boolean
          is_hot: boolean
          is_recommended: boolean
          main_camera_pixels: number | null
          monthly_browse: number | null
          monthly_sales: number | null
          name: string
          name_desc_tags_embedding: string | null
          pixel: string | null
          praise_rate: number | null
          price: number
          ram: string | null
          ram_gb: number | null
          refresh_rate: number | null
          release_date: string | null
          screen_refresh_rate: string | null
          screen_size: number | null
          soc_score: number | null
          specifications: Json | null
          specifications_text: string | null
          stock_quantity: number
          storage_gb: number | null
          thickness_mm: number | null
          updated_at: string
          video_url: string | null
          weight_g: number | null
          width_mm: number | null
        }
        Insert: {
          battery_capacity?: string | null
          battery_mah?: number | null
          brand?: string | null
          category?: string | null
          charging_power?: number | null
          comment_tags?: string | null
          core_processor?: string | null
          created_at?: string
          description?: string | null
          front_camera_pixels?: number | null
          id?: string
          image_url?: string | null
          images?: string[] | null
          is_active?: boolean
          is_hot?: boolean
          is_recommended?: boolean
          main_camera_pixels?: number | null
          monthly_browse?: number | null
          monthly_sales?: number | null
          name: string
          name_desc_tags_embedding?: string | null
          pixel?: string | null
          praise_rate?: number | null
          price: number
          ram?: string | null
          ram_gb?: number | null
          refresh_rate?: number | null
          release_date?: string | null
          screen_refresh_rate?: string | null
          screen_size?: number | null
          soc_score?: number | null
          specifications?: Json | null
          specifications_text?: string | null
          stock_quantity?: number
          storage_gb?: number | null
          thickness_mm?: number | null
          updated_at?: string
          video_url?: string | null
          weight_g?: number | null
          width_mm?: number | null
        }
        Update: {
          battery_capacity?: string | null
          battery_mah?: number | null
          brand?: string | null
          category?: string | null
          charging_power?: number | null
          comment_tags?: string | null
          core_processor?: string | null
          created_at?: string
          description?: string | null
          front_camera_pixels?: number | null
          id?: string
          image_url?: string | null
          images?: string[] | null
          is_active?: boolean
          is_hot?: boolean
          is_recommended?: boolean
          main_camera_pixels?: number | null
          monthly_browse?: number | null
          monthly_sales?: number | null
          name?: string
          name_desc_tags_embedding?: string | null
          pixel?: string | null
          praise_rate?: number | null
          price?: number
          ram?: string | null
          ram_gb?: number | null
          refresh_rate?: number | null
          release_date?: string | null
          screen_refresh_rate?: string | null
          screen_size?: number | null
          soc_score?: number | null
          specifications?: Json | null
          specifications_text?: string | null
          stock_quantity?: number
          storage_gb?: number | null
          thickness_mm?: number | null
          updated_at?: string
          video_url?: string | null
          weight_g?: number | null
          width_mm?: number | null
        }
        Relationships: []
      }
      profiles: {
        Row: {
          avatar_url: string | null
          bio: string | null
          created_at: string
          display_name: string | null
          email_verified: boolean | null
          id: string
          last_login: string | null
          phone: string | null
          role: string | null
          updated_at: string
          user_id: string
        }
        Insert: {
          avatar_url?: string | null
          bio?: string | null
          created_at?: string
          display_name?: string | null
          email_verified?: boolean | null
          id?: string
          last_login?: string | null
          phone?: string | null
          role?: string | null
          updated_at?: string
          user_id: string
        }
        Update: {
          avatar_url?: string | null
          bio?: string | null
          created_at?: string
          display_name?: string | null
          email_verified?: boolean | null
          id?: string
          last_login?: string | null
          phone?: string | null
          role?: string | null
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      recharge_plans: {
        Row: {
          bonus_amount: number
          created_at: string
          description: string | null
          display_order: number | null
          id: string
          is_active: boolean
          name: string
          recharge_amount: number
          updated_at: string
        }
        Insert: {
          bonus_amount?: number
          created_at?: string
          description?: string | null
          display_order?: number | null
          id?: string
          is_active?: boolean
          name: string
          recharge_amount: number
          updated_at?: string
        }
        Update: {
          bonus_amount?: number
          created_at?: string
          description?: string | null
          display_order?: number | null
          id?: string
          is_active?: boolean
          name?: string
          recharge_amount?: number
          updated_at?: string
        }
        Relationships: []
      }
      sms_verification_codes: {
        Row: {
          attempts: number | null
          code: string | null
          created_at: string | null
          expires_at: string
          id: string
          phone: string
          verified: boolean | null
        }
        Insert: {
          attempts?: number | null
          code?: string | null
          created_at?: string | null
          expires_at: string
          id?: string
          phone: string
          verified?: boolean | null
        }
        Update: {
          attempts?: number | null
          code?: string | null
          created_at?: string | null
          expires_at?: string
          id?: string
          phone?: string
          verified?: boolean | null
        }
        Relationships: []
      }
      system_guide: {
        Row: {
          doc_json: Json | null
          doc_markdown: string
          id: string
          sha256: string | null
          status: string
          title: string
          updated_at: string
          updated_by: string | null
          version: string
        }
        Insert: {
          doc_json?: Json | null
          doc_markdown: string
          id: string
          sha256?: string | null
          status: string
          title: string
          updated_at?: string
          updated_by?: string | null
          version: string
        }
        Update: {
          doc_json?: Json | null
          doc_markdown?: string
          id?: string
          sha256?: string | null
          status?: string
          title?: string
          updated_at?: string
          updated_by?: string | null
          version?: string
        }
        Relationships: []
      }
      tenant_profiles: {
        Row: {
          company_name: string | null
          context_snapshot: Json | null
          created_at: string
          first_natural_input: string | null
          first_task_completed: boolean | null
          id: string
          inferred_problem_type: string | null
          metadata: Json | null
          onboarding_completed_at: string | null
          updated_at: string
          user_id: string
        }
        Insert: {
          company_name?: string | null
          context_snapshot?: Json | null
          created_at?: string
          first_natural_input?: string | null
          first_task_completed?: boolean | null
          id?: string
          inferred_problem_type?: string | null
          metadata?: Json | null
          onboarding_completed_at?: string | null
          updated_at?: string
          user_id: string
        }
        Update: {
          company_name?: string | null
          context_snapshot?: Json | null
          created_at?: string
          first_natural_input?: string | null
          first_task_completed?: boolean | null
          id?: string
          inferred_problem_type?: string | null
          metadata?: Json | null
          onboarding_completed_at?: string | null
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      user_balances: {
        Row: {
          balance: number
          created_at: string
          id: string
          total_bonus: number
          total_consumed: number
          total_recharged: number
          updated_at: string
          user_id: string
        }
        Insert: {
          balance?: number
          created_at?: string
          id?: string
          total_bonus?: number
          total_consumed?: number
          total_recharged?: number
          updated_at?: string
          user_id: string
        }
        Update: {
          balance?: number
          created_at?: string
          id?: string
          total_bonus?: number
          total_consumed?: number
          total_recharged?: number
          updated_at?: string
          user_id?: string
        }
        Relationships: []
      }
      user_coupons: {
        Row: {
          coupon_id: string
          created_at: string | null
          id: string
          order_id: string | null
          received_at: string | null
          status: string
          used_at: string | null
          user_id: string
        }
        Insert: {
          coupon_id: string
          created_at?: string | null
          id?: string
          order_id?: string | null
          received_at?: string | null
          status?: string
          used_at?: string | null
          user_id: string
        }
        Update: {
          coupon_id?: string
          created_at?: string | null
          id?: string
          order_id?: string | null
          received_at?: string | null
          status?: string
          used_at?: string | null
          user_id?: string
        }
        Relationships: [
          {
            foreignKeyName: "user_coupons_coupon_id_fkey"
            columns: ["coupon_id"]
            isOneToOne: false
            referencedRelation: "coupons"
            referencedColumns: ["id"]
          },
          {
            foreignKeyName: "user_coupons_order_id_fkey"
            columns: ["order_id"]
            isOneToOne: false
            referencedRelation: "orders"
            referencedColumns: ["id"]
          },
        ]
      }
      user_roles: {
        Row: {
          created_at: string
          created_by: string | null
          id: string
          role: Database["public"]["Enums"]["app_role"]
          user_id: string
        }
        Insert: {
          created_at?: string
          created_by?: string | null
          id?: string
          role: Database["public"]["Enums"]["app_role"]
          user_id: string
        }
        Update: {
          created_at?: string
          created_by?: string | null
          id?: string
          role?: Database["public"]["Enums"]["app_role"]
          user_id?: string
        }
        Relationships: []
      }
    }
    Views: {
      admin_conversation_stats: {
        Row: {
          avatar_url: string | null
          department: string | null
          display_name: string | null
          is_active: boolean | null
          last_conversation_at: string | null
          position: string | null
          total_messages: number | null
          user_id: string | null
        }
        Relationships: []
      }
      products_search_view: {
        Row: {
          category: string | null
          description: string | null
          id: string | null
          name: string | null
          price: number | null
        }
        Insert: {
          category?: string | null
          description?: string | null
          id?: string | null
          name?: string | null
          price?: number | null
        }
        Update: {
          category?: string | null
          description?: string | null
          id?: string | null
          name?: string | null
          price?: number | null
        }
        Relationships: []
      }
    }
    Functions: {
      cleanup_expired_sms_codes: { Args: never; Returns: undefined }
      ensure_realtime_month_partitions: { Args: never; Returns: undefined }
      get_admin_conversation_history: {
        Args: { admin_user_id: string; limit_count?: number }
        Returns: {
          actions: Json
          admin_department: string
          admin_name: string
          content: string
          created_at: string
          message_id: string
          role: string
        }[]
      }
      get_current_user_role: { Args: never; Returns: string }
      get_current_user_role_secure: { Args: never; Returns: string }
      get_user_profile: {
        Args: { user_uuid: string }
        Returns: {
          avatar_url: string
          bio: string
          created_at: string
          display_name: string
          email_verified: boolean
          id: string
          last_login: string
          phone: string
          role: string
          updated_at: string
          user_id: string
        }[]
      }
      has_role: {
        Args: {
          _role: Database["public"]["Enums"]["app_role"]
          _user_id: string
        }
        Returns: boolean
      }
      is_admin: { Args: { _user_id: string }; Returns: boolean }
      is_owner: { Args: never; Returns: boolean }
      merge_anonymous_user_data: {
        Args: { anon_user_id: string; target_user_id: string }
        Returns: Json
      }
      rpc_products_search:
        | {
            Args: {
              in_keyword?: string
              in_limit?: number
              in_patterns?: string[]
            }
            Returns: {
              brand: string
              category: string
              id: string
              name: string
              price: number
            }[]
          }
        | {
            Args: { in_keyword: string; limit_count?: number }
            Returns: {
              category: string
              id: string
              name: string
              price: number
            }[]
          }
      search_knowledge_base: {
        Args: {
          filter_category?: string
          match_count?: number
          min_similarity?: number
          query_embedding: string
        }
        Returns: {
          category: string
          content: string
          id: string
          similarity: number
          source_path: string
          source_type: string
          tags: string[]
          title: string
        }[]
      }
      search_products_hzh: {
        Args: {
          p_battery_capacity: string
          p_brands: string[]
          p_category: string
          p_comment_tags: string
          p_core_proccessor: string
          p_limit: number
          p_name: string
          p_pixel: string
          p_price_max: number
          p_price_min: number
          p_query_vec: string
          p_ram: string
          p_screen_refresh_rate: string
          p_sort: string
        }
        Returns: {
          battery_capacity: string
          brand: string
          comment_tags: string
          core_processor: string
          created_at: string
          description: string
          id: string
          monthly_browse: number
          monthly_sales: number
          name: string
          pixel: string
          praise_rate: number
          price: number
          ram: string
          screen_refresh_rate: string
          stock_quantity: number
        }[]
      }
      search_products_phones: {
        Args: { match_count?: number; query_embedding: string }
        Returns: {
          brand: string
          description: string
          id: number
          name: string
          price: number
          similarity: number
        }[]
      }
      setup_speech_to_text: { Args: never; Returns: undefined }
      show_limit: { Args: never; Returns: number }
      show_trgm: { Args: { "": string }; Returns: string[] }
    }
    Enums: {
      alert_category:
        | "inventory"
        | "order"
        | "marketing"
        | "finance"
        | "service"
        | "system"
      alert_severity: "info" | "warning" | "critical"
      app_role: "admin" | "super_admin" | "user"
    }
    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: {
      alert_category: [
        "inventory",
        "order",
        "marketing",
        "finance",
        "service",
        "system",
      ],
      alert_severity: ["info", "warning", "critical"],
      app_role: ["admin", "super_admin", "user"],
    },
  },
} as const
