"use server";

import {createAdminClient} from "@/lib/backend/server-appwrite";
import {Databases, Query} from "node-appwrite";
import {ClientProfile} from "@/lib/backend/appwrite_types";

export async function listPlatformClients() {
    const {client} = await createAdminClient();
    const databases = new Databases(client);
    let clientsListResponse = await databases.listDocuments(
        process.env.NEXT_APPWRITE_DATABASE_ID!,
        process.env.NEXT_APPWRITE_CLIENTS_COLLECTION_ID!,
        [Query.orderDesc("$updatedAt"), Query.limit(20)]
    )

    return {
        doctors: clientsListResponse.documents as ClientProfile[],
        total: clientsListResponse.total as number
    }
}