const path = require("path");

const ENVIRONMENTS = {
  DEVELOPMENT: "development",
  PRODUCTION: "production",
};

const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  CONFLICT: 409,
  TOO_MANY_REQUESTS: 429,
  INTERNAL_ERROR: 500,
  SERVICE_UNAVAILABLE: 503,
};

const RATE_LIMITS = {
  API: {
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 100,
  },
  AUTH: {
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 50, // Increased from 5 to 50 for development
  },
  UPLOAD: {
    windowMs: 60 * 60 * 1000, // 1 hour
    max: 50,
  },
};

const SESSION_CONFIG = {
  COOKIE_MAX_AGE: 24 * 60 * 60 * 1000, // 24 hours
  SESSION_NAME: "skyartshop.sid",
};

const BODY_PARSER_LIMITS = {
  JSON: "10mb",
  URLENCODED: "10mb",
};

const isDevelopment = () => process.env.NODE_ENV !== ENVIRONMENTS.PRODUCTION;

const getBaseDir = () =>
  isDevelopment()
    ? path.join(__dirname, "..", "..", "website")
    : "/var/www/skyartshop";

const CRITICAL_IMAGES = [
  "/assets/images/hero-image.jpg",
  "/assets/images/products/placeholder.jpg",
];

const STATIC_ASSET_EXTENSIONS =
  /\.(jpg|jpeg|png|gif|svg|css|js|ico|webp|woff|woff2|ttf|eot)$/i;

const PG_ERROR_CODES = {
  UNIQUE_VIOLATION: "23505",
  FOREIGN_KEY_VIOLATION: "23503",
  INVALID_TEXT: "22P02",
};

const MULTER_ERROR_CODES = {
  FILE_SIZE: "LIMIT_FILE_SIZE",
  FILE_COUNT: "LIMIT_FILE_COUNT",
};

module.exports = {
  ENVIRONMENTS,
  HTTP_STATUS,
  RATE_LIMITS,
  SESSION_CONFIG,
  BODY_PARSER_LIMITS,
  CRITICAL_IMAGES,
  STATIC_ASSET_EXTENSIONS,
  PG_ERROR_CODES,
  MULTER_ERROR_CODES,
  isDevelopment,
  getBaseDir,
};
