import dotenv from 'dotenv';
import path from 'node:path';

dotenv.config();

export const config = {
  port: Number(process.env.PORT || 3100),
  sessionSecret: process.env.SESSION_SECRET || 'change-me',
  authUsername: process.env.AUTH_USERNAME || 'admin',
  authPassword: process.env.AUTH_PASSWORD || '',
  databasePath: path.resolve(process.cwd(), process.env.DATABASE_PATH || './management.sqlite'),
  corsOrigins: (process.env.CORS_ORIGINS || 'http://localhost:5173')
    .split(',')
    .map((value) => value.trim())
    .filter(Boolean),
  sessionCookieSecure: process.env.SESSION_COOKIE_SECURE
    ? process.env.SESSION_COOKIE_SECURE === 'true'
    : process.env.NODE_ENV === 'production',
  allowInsecureAgentHttp: process.env.ALLOW_INSECURE_AGENT_HTTP === 'true',
  agentCaFile: process.env.AGENT_CA_FILE ? path.resolve(process.cwd(), process.env.AGENT_CA_FILE) : '',
};
