export function getPropertyImageUrl(fileId: string): string {
  const endpoint = (process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT ?? "").replace(/\/$/, "");
  const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID ?? "";
  return `${endpoint}/storage/buckets/property-images/files/${fileId}/view?project=${projectId}`;
}

export function getPropertyImagePreviewUrl(fileId: string, width = 800, height = 600): string {
  const endpoint = (process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT ?? "").replace(/\/$/, "");
  const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID ?? "";
  return `${endpoint}/storage/buckets/property-images/files/${fileId}/preview?project=${projectId}&width=${width}&height=${height}&quality=85`;
}

export function parseImageIds(imageIds?: string | null): string[] {
  if (!imageIds) return [];
  try {
    const arr = JSON.parse(imageIds);
    return Array.isArray(arr) ? arr : [];
  } catch {
    return [];
  }
}
