import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://mgqefaxhfmgkoqeachgi.supabase.co'
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'sb_publishable_T2pJmKz7HIFy4WuT-6eknw_kYckbItP'

export const supabase = createClient(supabaseUrl, supabaseAnonKey)

// Database types
export interface Database {
  public: {
    Tables: {
      trades: {
        Row: {
          id: string
          user_id: string
          pair: string
          direction: 'long' | 'short'
          entry_price: number
          exit_price?: number
          status: 'open' | 'closed'
          is_demo: boolean
          trader_style: string
          setup: string
          timeframe: string
          pnl?: number
          pnl_percent?: number
          opened_at: string
          closed_at?: string
          created_at: string
        }
        Insert: Omit<Database['public']['Tables']['trades']['Row'], 'id' | 'created_at'>
        Update: Partial<Database['public']['Tables']['trades']['Insert']>
      }
      tasks: {
        Row: {
          id: string
          user_id: string
          title: string
          description?: string
          status: 'pending' | 'in_progress' | 'completed'
          priority: 'low' | 'medium' | 'high'
          due_date?: string
          created_at: string
        }
        Insert: Omit<Database['public']['Tables']['tasks']['Row'], 'id' | 'created_at'>
        Update: Partial<Database['public']['Tables']['tasks']['Insert']>
      }
      leads: {
        Row: {
          id: string
          user_id: string
          name: string
          business_name?: string
          phone?: string
          email?: string
          source?: string
          status: 'new' | 'contacted' | 'qualified' | 'won' | 'lost'
          notes?: string
          created_at: string
        }
        Insert: Omit<Database['public']['Tables']['leads']['Row'], 'id' | 'created_at'>
        Update: Partial<Database['public']['Tables']['leads']['Insert']>
      }
    }
  }
}
