const fs = require('fs');
const path = require('path');

// SSL Configuration (optional - only needed if not using Traefik/reverse proxy)
const sslConfig = process.env.USE_SSL === 'true' ? {
  key: fs.readFileSync(process.env.SSL_KEY_PATH || '/etc/httpd/ssl/crewsportswear_app.key', 'utf8'),
  cert: fs.readFileSync(process.env.SSL_CERT_PATH || '/etc/httpd/ssl/certs/current_cert.crt', 'utf8')
} : null;

// CORS Configuration
const allowedOrigins = [
  'http://uniformnetwork.com',
  'http://localhost',
  'https://crewsportswear.com',
  'https://crewsportswear.app',
  'https://merchbay.com'
];

// Screenshot Configuration
const screenshotConfig = {
  outputDir: process.env.OUTPUT_DIR || '/var/www/html/images/',
  baseUrl: process.env.BASE_URL || 'https://crewsportswear.app:5955/',
  viewportWidth: parseInt(process.env.VIEWPORT_WIDTH || '1366'),
  viewportHeight: parseInt(process.env.VIEWPORT_HEIGHT || '1100'),
  waitTime: parseInt(process.env.WAIT_TIME || '10000'), // milliseconds
  puppeteerArgs: ['--no-sandbox', '--disable-setuid-sandbox']
};

// Server Configuration
const serverConfig = {
  port: process.env.PORT || 5955,
  host: process.env.HOST || '0.0.0.0',
  useSSL: process.env.USE_SSL === 'true'
};

// Design viewer URLs
const viewerUrls = {
  crewsportswear: 'https://crewsportswear.com/designer/viewer/',
  merchbay: 'https://crewsportswear.com/designer/merchbay-viewer/',
  merchbayLegacy: 'https://crewsportswear.com/designer/merchbay-viewer.php?id='
};

module.exports = {
  sslConfig,
  allowedOrigins,
  screenshotConfig,
  serverConfig,
  viewerUrls
};
