"use server";
import { eq, not , asc} from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { db } from "../db";
import { brand } from "@db/schema/Brand";
export const getData = async () => {
  const data = await db.select().from(brand).orderBy(asc(brand.name));
  return data;
};

export const addBrand = async ( name: string) => {
  await db.insert(brand).values({
    name: name,
  });
};

export const deleteBrand = async (id: number) => {
  "use server";
  await db.delete(brand).where(eq(brand.id, id));
  revalidatePath("/Brands");
};

export const editBrand = async (id: number, name: string) => {
  await db
    .update(brand)
    .set({
      name: name,
    })
    .where(eq(brand.id, id));
  revalidatePath("/");
};