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

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

if (!supabaseUrl || !supabaseAnonKey) {
  console.error('Missing Supabase environment variables. Please check your .env file.');
}

// Fallback to dummy values to prevent app crash, but API calls will fail
export const supabase = createClient(
  supabaseUrl || 'https://placeholder.supabase.co',
  supabaseAnonKey || 'placeholder'
);

export type Database = {
  public: {
    Tables: {
      files: {
        Row: {
          id: string;
          user_id: string | null;
          filename: string;
          file_path: string;
          file_type: string;
          file_size: number;
          thumbnail_path: string | null;
          status: string;
          created_at: string;
          updated_at: string;
        };
        Insert: {
          id?: string;
          user_id?: string | null;
          filename: string;
          file_path: string;
          file_type: string;
          file_size?: number;
          thumbnail_path?: string | null;
          status?: string;
          created_at?: string;
          updated_at?: string;
        };
        Update: {
          id?: string;
          user_id?: string | null;
          filename?: string;
          file_path?: string;
          file_type?: string;
          file_size?: number;
          thumbnail_path?: string | null;
          status?: string;
          created_at?: string;
          updated_at?: string;
        };
      };
      recognition_results: {
        Row: {
          id: string;
          file_id: string;
          markdown_content: string | null;
          latex_content: string | null;
          mathml_content: string | null;
          mml: string | null;
          rendered_image_path: string | null;
          created_at: string;
        };
        Insert: {
          id?: string;
          file_id: string;
          markdown_content?: string | null;
          latex_content?: string | null;
          mathml_content?: string | null;
          mml?: string | null;
          rendered_image_path?: string | null;
          created_at?: string;
        };
        Update: {
          id?: string;
          file_id?: string;
          markdown_content?: string | null;
          latex_content?: string | null;
          mathml_content?: string | null;
          mml?: string | null;
          rendered_image_path?: string | null;
          created_at?: string;
        };
      };
    };
  };
};
