// db/queries.ts
"use server";
import { eq, not , asc} from "drizzle-orm";
import { accounts } from '@schemas/schema'
import { db } from '../../index';

// Fetch all account
export async function getAllAccounts() {
  return await db.select().from(accounts);
}

// Add a new account
export async function addAcount(first_name: string, last_name : string, username : string, password_hash: string ) {
  return await db.insert(accounts).values({ first_name, last_name, username, password_hash }).returning();
}

// Update a account
export async function updateAcount(id: number, first_name: string, last_name : string, username : string, password_hash: string ) {
  return await db.update(accounts).set({ first_name, last_name, username, password_hash }).where(eq(accounts.id, id));
}

// Delete a account
export async function deleteAccount(id: number) {
  return await db.delete(accounts).where(eq(accounts.id, id));
}