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

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

// Add a new account
export async function addAcount(first_name: string, last_name : string, username : string, password_hash: string ) {
  return await db.insert(Account).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(Account).set({ first_name, last_name, username, password_hash }).where(eq(Account.id, id));
}

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