"use server"

import prisma from "@/lib/prisma";

export async function getPortfolioFilters() {
  const albums = await prisma.portfolioAlbum.findMany({
    where: {
      // images: {
      //   some: {
      //     published: true,
      //   },
      // },
    },
    select: {
      id: true,
      name: true,
    },
    orderBy: {
      sortIndex: "asc",
    },
  });

  const yearsRaw = await prisma.portfolioImage.findMany({
    where: {
      // published: true,
      year: {
        not: null,
      },
    },
    distinct: ["year"],
    select: {
      year: true,
    },
  });

  const years = yearsRaw
    .map((y) => y.year!)
    .sort((a, b) => b - a)
    .map(String);

  return { albums, years };
}
