import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { config } from "dotenv";
import { z } from "zod";

config({
  path: resolve(dirname(fileURLToPath(import.meta.url)), "../../../../.env"),
});

const envSchema = z.object({
  NODE_ENV: z.string().default("development"),
  DATABASE_URL: z.string().url(),
  API_HOST: z.string().default("0.0.0.0"),
  API_PORT: z.coerce.number().int().positive().default(4020),
  ADMIN_TOKEN: z.string().min(12),
  PUSH_SECRET_ENCRYPTION_KEY: z.string().min(24),
  PUBLIC_BASE_URL: z.string().url().default("http://localhost:4020"),
  WEB_PUSH_PUBLIC_KEY: z.string().optional().default(""),
  WEB_PUSH_PRIVATE_KEY: z.string().optional().default(""),
  IOS_BUNDLE_ID: z.string().default("software.federspiel.fedeo"),
  APNS_TEAM_ID: z.string().optional().default(""),
  APNS_KEY_ID: z.string().optional().default(""),
  APNS_PRIVATE_KEY: z.string().optional().default(""),
  APNS_PRODUCTION: z.coerce.boolean().default(false),
  ANDROID_SENDER_ID: z.string().optional().default(""),
  FCM_PROJECT_ID: z.string().optional().default(""),
  FCM_SERVICE_ACCOUNT_JSON: z.string().optional().default(""),
});

export const env = envSchema.parse(process.env);
