import "server-only";

import { BUCKETS } from "./schema";

const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT?.replace(/\/$/, "") ?? "";
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID ?? "";

export function getFileViewUrl(bucketId: string, fileId: string): string {
  if (!ENDPOINT || !PROJECT_ID || !fileId) return "";
  return `${ENDPOINT}/storage/buckets/${bucketId}/files/${fileId}/view?project=${PROJECT_ID}`;
}

export function getLogoUrl(fileId?: string | null): string | null {
  if (!fileId) return null;
  return getFileViewUrl(BUCKETS.tenantLogos, fileId);
}
