import { db } from "@/lib/db";

export type SiteSettings = Awaited<ReturnType<typeof getSettings>>;

export async function getSettings() {
  const s = await db.siteSetting.findUnique({ where: { id: "singleton" } });
  return s;
}

export async function getServices() {
  return db.service.findMany({
    where: { isEnabled: true },
    orderBy: { order: "asc" },
  });
}

export async function getAllServices() {
  return db.service.findMany({ orderBy: { order: "asc" } });
}

export async function getFeaturedProjects(limit = 6) {
  return db.project.findMany({
    where: { isEnabled: true, isFeatured: true },
    orderBy: { createdAt: "desc" },
    take: limit,
  });
}

export async function getProjects() {
  return db.project.findMany({
    where: { isEnabled: true },
    orderBy: { createdAt: "desc" },
  });
}

export async function getBeforeAfters() {
  return db.beforeAfter.findMany({
    where: { isEnabled: true },
    orderBy: { order: "asc" },
  });
}

export async function getTestimonials() {
  return db.testimonial.findMany({
    where: { isEnabled: true },
    orderBy: { order: "asc" },
  });
}

export async function getIndustries() {
  return db.industry.findMany({
    where: { isEnabled: true },
    orderBy: { order: "asc" },
  });
}

export async function getFaqs() {
  return db.faq.findMany({
    where: { isEnabled: true },
    orderBy: { order: "asc" },
  });
}

export async function getPublishedPosts(limit?: number) {
  return db.blogPost.findMany({
    where: { isPublished: true },
    orderBy: { publishedAt: "desc" },
    ...(limit ? { take: limit } : {}),
  });
}
