import {initializeApp} from "firebase/app";
import * as admin from "firebase-admin/app";
import {getStorage} from "firebase/storage";

const stagingServiceAccount = require("@/constants/staging.json");
const platformServiceAccount = require("@/constants/platform.json");

const firebaseConfig = {
	apiKey: process.env.FIREBASE_PUBLIC_API_KEY || "",
	authDomain: process.env.FIREBASE_AUTH_DOMAIN || "",
	projectId: process.env.FIREBASE_PROJECT_ID || "",
	storageBucket: process.env.FIREBASE_STORAGE_BUCKET || "",
	messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID || "",
	appId: process.env.FIREBASE_APP_ID || "",
};

export const app = initializeApp(firebaseConfig, Math.random().toString());
export const adminApp = admin.initializeApp(
	{
		credential: admin.cert(process.env.ENVIRONMENT === "platform" ? platformServiceAccount : stagingServiceAccount),
	},
	Math.random().toString(),
);
export const storage = getStorage(app);
