import * as Joi from 'joi';

export const configValidationSchema = Joi.object({
  // Application
  NODE_ENV: Joi.string().valid('development', 'production', 'test').default('development'),
  PORT: Joi.number().default(3001),
  API_PREFIX: Joi.string().default('api'),

  // Database
  DATABASE_URL: Joi.string().required(),

  // JWT / Keycloak
  JWT_SECRET: Joi.string().when('NODE_ENV', {
    is: 'production',
    then: Joi.required(),
    otherwise: Joi.string().default('dev-secret-key-change-in-production'),
  }),
  KEYCLOAK_URL: Joi.string().uri().optional(),
  KEYCLOAK_REALM: Joi.string().optional(),
  KEYCLOAK_CLIENT_ID: Joi.string().optional(),
  KEYCLOAK_CLIENT_SECRET: Joi.string().optional(),

  // Encryption
  ENCRYPTION_KEY: Joi.string().min(32).when('NODE_ENV', {
    is: 'production',
    then: Joi.required(),
    otherwise: Joi.optional(),
  }),

  // Keycloak Admin (for setup wizard)
  KEYCLOAK_ADMIN_PASSWORD: Joi.string().optional(),

  // Setup token (initial system setup)
  SETUP_TOKEN: Joi.string().optional(),

  // Redis (optional - for BullMQ in production)
  REDIS_HOST: Joi.string().optional(),
  REDIS_PORT: Joi.number().optional(),
});
