import { supabase } from '@/supabase';

export const usersService = {
    async searchUsers(email: string) {
        const { data, error } = await supabase.from('users').select('*').ilike('email', `%${email}%`)
        if (error) throw new Error(error.message)
        return data
    },

    async getUserDetails(userId: string) {
        const { data, error } = await supabase.from('users').select('*').eq('id', userId).single()
        if (error) throw new Error(error.message)
        return data
    },

    async getPendingDrivers() {
        const { data, error } = await supabase
            .from('driver_profiles')
            .select('*, user:users(*)')
            .eq('users.is_verified', false)
        if (error) throw new Error(error.message)
        return data
    },

    async verifyUser(userId: string, isVerified: boolean) {
        const { data, error } = await supabase
            .from('users')
            .update({ is_verified: isVerified })
            .eq('id', userId)
            .select()
            .single()
        if (error) throw new Error(error.message)
        return data
    }
};
