import { z } from 'zod';

const monitoringEnvSchema = z.object({
  DD_SERVICE: z.string().default('shieldai-api'),
  DD_ENV: z.string().default(process.env.NODE_ENV || 'development'),
  DD_VERSION: z.string().default('0.1.0'),
  DD_TRACE_ENABLED: z.string().default('true'),
  DD_TRACE_SAMPLE_RATE: z.string().transform((v) => Number(v)).default('1.0'),
  DD_LOGS_INJECTION: z.string().default('true'),
  DD_API_KEY: z.string().default(''),
  DD_SITE: z.string().default('datadoghq.com'),
  DD_AGENT_HOST: z.string().default('localhost'),
  DD_AGENT_PORT: z.string().transform((v) => Number(v)).default('8126'),
  SENTRY_DSN: z.string().default(''),
  SENTRY_ENVIRONMENT: z.string().default(process.env.NODE_ENV || 'development'),
  SENTRY_RELEASE: z.string().default('0.1.0'),
  SENTRY_TRACES_SAMPLE_RATE: z.string().transform((v) => Number(v)).default('0.1'),
});

export type MonitoringConfig = z.infer<typeof monitoringEnvSchema>;

export function getMonitoringConfig(): MonitoringConfig {
  return monitoringEnvSchema.parse({
    DD_SERVICE: process.env.DD_SERVICE,
    DD_ENV: process.env.DD_ENV,
    DD_VERSION: process.env.DD_VERSION,
    DD_TRACE_ENABLED: process.env.DD_TRACE_ENABLED,
    DD_TRACE_SAMPLE_RATE: process.env.DD_TRACE_SAMPLE_RATE,
    DD_LOGS_INJECTION: process.env.DD_LOGS_INJECTION,
    DD_API_KEY: process.env.DD_API_KEY,
    DD_SITE: process.env.DD_SITE,
    DD_AGENT_HOST: process.env.DD_AGENT_HOST,
    DD_AGENT_PORT: process.env.DD_AGENT_PORT,
    SENTRY_DSN: process.env.SENTRY_DSN,
    SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT,
    SENTRY_RELEASE: process.env.SENTRY_RELEASE,
    SENTRY_TRACES_SAMPLE_RATE: process.env.SENTRY_TRACES_SAMPLE_RATE,
  });
}
