import { db } from "@/app/db/db";
import {
  SolarInterface,
  solar,
  SolarScenario,
  solarScenario,
} from "@/app/db/schema/solar";
import { eq, and } from "drizzle-orm";

export async function getSolarData(uprn: number): Promise<SolarInterface> {
  const data = await db.query.solar.findFirst({
    where: eq(solar.uprn, BigInt(uprn)),
  });

  return data as SolarInterface;
}

export async function getSolarScenarioData(
  solarId: string
): Promise<SolarScenario> {
  const data = await db.query.solarScenario.findFirst({
    where: (solarScenario, { eq, and }) =>
      and(
        eq(solarScenario.solarId, BigInt(solarId)),
        eq(solarScenario.isDefault, true)
      ),
  });

  return data as SolarScenario;
}
