import { and, eq } from "drizzle-orm"; import { db } from "@/lib/db"; import { gardenContainers, gardenPlants } from "../schema"; export type ContainerShareData = { id: string; name: string; type: string; locationNotes: string | null; coverImageUrl: string | null; plants: { id: string; name: string; scientificName: string | null }[]; }; export type PlantShareData = { id: string; name: string; scientificName: string | null; primaryImageUrl: string | null; images: string[]; healthStatus: string; growthStage: string | null; category: string; wateringNotes: string | null; fertilizingNotes: string | null; notes: string | null; sunlight: string | null; }; export async function loadPlantForShare(id: string): Promise { const [plant] = await db .select({ id: gardenPlants.id, name: gardenPlants.name, scientificName: gardenPlants.scientificName, primaryImageUrl: gardenPlants.primaryImageUrl, images: gardenPlants.images, healthStatus: gardenPlants.healthStatus, growthStage: gardenPlants.growthStage, category: gardenPlants.category, wateringNotes: gardenPlants.wateringNotes, fertilizingNotes: gardenPlants.fertilizingNotes, notes: gardenPlants.notes, sunlight: gardenPlants.sunlight, }) .from(gardenPlants) .where(eq(gardenPlants.id, id)) .limit(1); if (!plant) return null; return plant; } export async function loadContainerForShare(id: string): Promise { const [container] = await db .select() .from(gardenContainers) .where(eq(gardenContainers.id, id)) .limit(1); if (!container) return null; const plants = await db .select({ id: gardenPlants.id, name: gardenPlants.name, scientificName: gardenPlants.scientificName, }) .from(gardenPlants) .where(and(eq(gardenPlants.containerId, id))); return { id: container.id, name: container.name, type: container.type, locationNotes: container.locationNotes, coverImageUrl: container.coverImageUrl, plants, }; }