apiVersion: v1
kind: ConfigMap
metadata:
  name: bakery-config
  namespace: bakery-ia
  labels:
    app.kubernetes.io/name: bakery-ia
    app.kubernetes.io/component: config
data:
  # ================================================================
  # ENVIRONMENT & BUILD SETTINGS
  # ================================================================
  ENVIRONMENT: "development"
  DEBUG: "false"
  LOG_LEVEL: "INFO"

  # Observability Settings
  # Set to "true" when Jaeger/monitoring stack is deployed
  ENABLE_TRACING: "false"

  # Database initialization settings
  # IMPORTANT: Services NEVER run migrations - they only verify DB is ready
  # Migrations are handled by dedicated migration jobs
  # DB_FORCE_RECREATE only affects migration jobs, not services
  DB_FORCE_RECREATE: "false"
  BUILD_DATE: "2024-01-20T10:00:00Z"
  VCS_REF: "latest"
  IMAGE_TAG: "latest"
  DOMAIN: "bakery.yourdomain.com"
  AUTO_RELOAD: "false"
  PROFILING_ENABLED: "false"
  MOCK_EXTERNAL_APIS: "false"
  TESTING: "false"

  # ================================================================
  # SERVICE DISCOVERY (KUBERNETES INTERNAL)
  # ================================================================
  REDIS_HOST: "redis-service"
  REDIS_PORT: "6379"
  RABBITMQ_HOST: "rabbitmq-service"
  RABBITMQ_PORT: "5672"
  RABBITMQ_MANAGEMENT_PORT: "15672"
  RABBITMQ_VHOST: "/"

  # Database Hosts (Kubernetes Services)
  AUTH_DB_HOST: "auth-db-service"
  TENANT_DB_HOST: "tenant-db-service"
  TRAINING_DB_HOST: "training-db-service"
  FORECASTING_DB_HOST: "forecasting-db-service"
  SALES_DB_HOST: "sales-db-service"
  EXTERNAL_DB_HOST: "external-db-service"
  NOTIFICATION_DB_HOST: "notification-db-service"
  INVENTORY_DB_HOST: "inventory-db-service"
  RECIPES_DB_HOST: "recipes-db-service"
  SUPPLIERS_DB_HOST: "suppliers-db-service"
  POS_DB_HOST: "pos-db-service"
  ORDERS_DB_HOST: "orders-db-service"
  PRODUCTION_DB_HOST: "production-db-service"
  PROCUREMENT_DB_HOST: "procurement-db-service"
  ORCHESTRATOR_DB_HOST: "orchestrator-db-service"
  ALERT_PROCESSOR_DB_HOST: "alert-processor-db-service"
  AI_INSIGHTS_DB_HOST: "ai-insights-db-service"

  # Database Configuration
  DB_PORT: "5432"
  AUTH_DB_NAME: "auth_db"
  TENANT_DB_NAME: "tenant_db"
  TRAINING_DB_NAME: "training_db"
  FORECASTING_DB_NAME: "forecasting_db"
  SALES_DB_NAME: "sales_db"
  EXTERNAL_DB_NAME: "external_db"
  NOTIFICATION_DB_NAME: "notification_db"
  INVENTORY_DB_NAME: "inventory_db"
  RECIPES_DB_NAME: "recipes_db"
  SUPPLIERS_DB_NAME: "suppliers_db"
  POS_DB_NAME: "pos_db"
  ORDERS_DB_NAME: "orders_db"
  PRODUCTION_DB_NAME: "production_db"
  PROCUREMENT_DB_NAME: "procurement_db"
  ORCHESTRATOR_DB_NAME: "orchestrator_db"
  ALERT_PROCESSOR_DB_NAME: "alert_processor_db"
  AI_INSIGHTS_DB_NAME: "ai_insights_db"
  POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"

  # ================================================================
  # SERVICE URLS (KUBERNETES INTERNAL)
  # ================================================================
  GATEWAY_URL: "http://gateway-service:8000"
  AUTH_SERVICE_URL: "http://auth-service:8000"
  TENANT_SERVICE_URL: "http://tenant-service:8000"
  TRAINING_SERVICE_URL: "http://training-service:8000"
  FORECASTING_SERVICE_URL: "http://forecasting-service:8000"
  SALES_SERVICE_URL: "http://sales-service:8000"
  EXTERNAL_SERVICE_URL: "http://external-service:8000"
  NOTIFICATION_SERVICE_URL: "http://notification-service:8000"
  INVENTORY_SERVICE_URL: "http://inventory-service:8000"
  RECIPES_SERVICE_URL: "http://recipes-service:8000"
  SUPPLIERS_SERVICE_URL: "http://suppliers-service:8000"
  POS_SERVICE_URL: "http://pos-service:8000"
  ORDERS_SERVICE_URL: "http://orders-service:8000"
  PRODUCTION_SERVICE_URL: "http://production-service:8000"
  ALERT_PROCESSOR_SERVICE_URL: "http://alert-processor-api:8010"
  ORCHESTRATOR_SERVICE_URL: "http://orchestrator-service:8000"
  AI_INSIGHTS_SERVICE_URL: "http://ai-insights-service:8000"

  # ================================================================
  # AUTHENTICATION & SECURITY SETTINGS
  # ================================================================
  JWT_ALGORITHM: "HS256"
  JWT_ACCESS_TOKEN_EXPIRE_MINUTES: "240"
  JWT_REFRESH_TOKEN_EXPIRE_DAYS: "7"
  ENABLE_SERVICE_AUTH: "false"
  PASSWORD_MIN_LENGTH: "8"
  PASSWORD_REQUIRE_UPPERCASE: "true"
  PASSWORD_REQUIRE_LOWERCASE: "true"
  PASSWORD_REQUIRE_NUMBERS: "true"
  PASSWORD_REQUIRE_SYMBOLS: "false"
  BCRYPT_ROUNDS: "12"
  MAX_LOGIN_ATTEMPTS: "5"
  LOCKOUT_DURATION_MINUTES: "30"

  # ================================================================
  # CORS & API CONFIGURATION
  # ================================================================
  CORS_ORIGINS: "https://bakery.yourdomain.com,http://frontend-service:3000"
  CORS_ALLOW_CREDENTIALS: "true"
  RATE_LIMIT_ENABLED: "true"
  RATE_LIMIT_REQUESTS: "100"
  RATE_LIMIT_WINDOW: "60"
  RATE_LIMIT_BURST: "10"
  API_DOCS_ENABLED: "true"

  # ================================================================
  # HTTP CLIENT SETTINGS
  # ================================================================
  HTTP_TIMEOUT: "30000"
  HTTP_RETRIES: "3"
  HTTP_RETRY_DELAY: "1.0"

  # ================================================================
  # EXTERNAL API CONFIGURATION
  # ================================================================
  AEMET_BASE_URL: "https://opendata.aemet.es/opendata"
  AEMET_TIMEOUT: "90"
  AEMET_RETRY_ATTEMPTS: "5"
  MADRID_OPENDATA_BASE_URL: "https://datos.madrid.es"
  MADRID_OPENDATA_TIMEOUT: "30"

  # ================================================================
  # PAYMENT CONFIGURATION
  # ================================================================
  STRIPE_PUBLISHABLE_KEY: "pk_live_your_stripe_publishable_key_here"
  SQUARE_APPLICATION_ID: "your-square-application-id"
  SQUARE_ENVIRONMENT: "production"
  TOAST_ENVIRONMENT: "production"
  LIGHTSPEED_ENVIRONMENT: "production"

  # ================================================================
  # EMAIL CONFIGURATION
  # ================================================================
  SMTP_HOST: "smtp.gmail.com"
  SMTP_PORT: "587"
  SMTP_TLS: "true"
  SMTP_SSL: "false"
  DEFAULT_FROM_EMAIL: "noreply@bakeryforecast.es"
  DEFAULT_FROM_NAME: "Bakery-Forecast"
  EMAIL_FROM_ADDRESS: "alerts@bakery.local"
  EMAIL_FROM_NAME: "Bakery Alert System"

  # ================================================================
  # WHATSAPP CONFIGURATION
  # ================================================================
  WHATSAPP_BASE_URL: "https://api.twilio.com"
  WHATSAPP_FROM_NUMBER: "whatsapp:+14155238886"

  # ================================================================
  # ALERT SYSTEM CONFIGURATION
  # ================================================================
  ALERT_PROCESSOR_INSTANCES: "2"
  ALERT_PROCESSOR_MAX_MEMORY: "512M"
  ALERT_BATCH_SIZE: "10"
  ALERT_PROCESSING_TIMEOUT: "30"
  EMAIL_ENABLED: "true"
  WHATSAPP_ENABLED: "true"
  SSE_ENABLED: "true"
  PUSH_NOTIFICATIONS_ENABLED: "false"
  ALERT_DEDUPLICATION_WINDOW_MINUTES: "15"
  RECOMMENDATION_DEDUPLICATION_WINDOW_MINUTES: "60"

  # ================================================================
  # CHECK FREQUENCIES (CRON EXPRESSIONS)
  # ================================================================
  STOCK_CHECK_FREQUENCY: "*/5"
  EXPIRY_CHECK_FREQUENCY: "*/2"
  TEMPERATURE_CHECK_FREQUENCY: "*/2"
  PRODUCTION_DELAY_CHECK_FREQUENCY: "*/5"
  CAPACITY_CHECK_FREQUENCY: "*/10"
  INVENTORY_OPTIMIZATION_FREQUENCY: "*/30"
  EFFICIENCY_RECOMMENDATIONS_FREQUENCY: "*/30"
  ENERGY_RECOMMENDATIONS_FREQUENCY: "0"
  WASTE_REDUCTION_FREQUENCY: "0"

  # ================================================================
  # MODEL STORAGE & TRAINING
  # ================================================================
  MODEL_STORAGE_PATH: "/app/models"
  MODEL_BACKUP_ENABLED: "true"
  MODEL_VERSIONING_ENABLED: "true"
  MAX_TRAINING_TIME_MINUTES: "30"
  MAX_CONCURRENT_TRAINING_JOBS: "3"
  MIN_TRAINING_DATA_DAYS: "30"
  TRAINING_BATCH_SIZE: "1000"

  # ================================================================
  # OPTIMIZATION SETTINGS
  # ================================================================
  ENABLE_HYPERPARAMETER_OPTIMIZATION: "true"
  ENABLE_PRODUCT_SPECIFIC_PARAMS: "true"
  ENABLE_DYNAMIC_PARAM_SELECTION: "true"
  OPTUNA_N_TRIALS: "50"
  OPTUNA_CV_FOLDS: "3"
  OPTUNA_TIMEOUT_MINUTES: "10"
  HIGH_VOLUME_THRESHOLD: "1.0"
  INTERMITTENT_THRESHOLD: "0.6"

  # ================================================================
  # PROPHET PARAMETERS
  # ================================================================
  PROPHET_SEASONALITY_MODE: "additive"
  PROPHET_CHANGEPOINT_PRIOR_SCALE: "0.05"
  PROPHET_SEASONALITY_PRIOR_SCALE: "10.0"
  PROPHET_HOLIDAYS_PRIOR_SCALE: "10.0"
  PROPHET_DAILY_SEASONALITY: "true"
  PROPHET_WEEKLY_SEASONALITY: "true"
  PROPHET_YEARLY_SEASONALITY: "true"

  # ================================================================
  # BUSINESS CONFIGURATION
  # ================================================================
  SERVICE_VERSION: "1.0.0"
  TIMEZONE: "Europe/Madrid"
  LOCALE: "es_ES.UTF-8"
  CURRENCY: "EUR"
  BUSINESS_HOUR_START: "7"
  BUSINESS_HOUR_END: "20"
  ENABLE_SPANISH_HOLIDAYS: "true"
  ENABLE_MADRID_HOLIDAYS: "true"
  SCHOOL_CALENDAR_ENABLED: "true"
  WEATHER_IMPACT_ENABLED: "true"

  # ================================================================
  # MONITORING & LOGGING
  # ================================================================
  LOG_FORMAT: "json"
  LOG_FILE_ENABLED: "false"
  LOG_FILE_PATH: "/app/logs"
  LOG_ROTATION_SIZE: "100MB"
  LOG_RETENTION_DAYS: "30"
  PROMETHEUS_ENABLED: "true"
  PROMETHEUS_RETENTION: "200h"
  HEALTH_CHECK_TIMEOUT: "30"
  HEALTH_CHECK_INTERVAL: "30"
  PROMETHEUS_RETENTION_DAYS: "30"
  GRAFANA_ROOT_URL: "http://monitoring.bakery-ia.local/grafana"

  # ================================================================
  # DATA COLLECTION SETTINGS
  # ================================================================
  WEATHER_COLLECTION_INTERVAL_HOURS: "1"
  TRAFFIC_COLLECTION_INTERVAL_HOURS: "1"
  EVENTS_COLLECTION_INTERVAL_HOURS: "6"
  DATA_VALIDATION_ENABLED: "true"
  OUTLIER_DETECTION_ENABLED: "true"
  DATA_COMPLETENESS_THRESHOLD: "0.8"
  DEFAULT_LATITUDE: "40.4168"
  DEFAULT_LONGITUDE: "-3.7038"
  LOCATION_RADIUS_KM: "50.0"

  # ================================================================
  # NOTIFICATION SETTINGS
  # ================================================================
  ENABLE_EMAIL_NOTIFICATIONS: "true"
  ENABLE_WHATSAPP_NOTIFICATIONS: "true"
  ENABLE_PUSH_NOTIFICATIONS: "false"
  MAX_RETRY_ATTEMPTS: "3"
  RETRY_DELAY_SECONDS: "60"
  NOTIFICATION_BATCH_SIZE: "100"
  EMAIL_RATE_LIMIT_PER_HOUR: "1000"
  WHATSAPP_RATE_LIMIT_PER_HOUR: "100"
  DEFAULT_LANGUAGE: "es"
  DATE_FORMAT: "%d/%m/%Y"
  TIME_FORMAT: "%H:%M"
  EMAIL_TEMPLATES_PATH: "/app/templates/email"
  WHATSAPP_TEMPLATES_PATH: "/app/templates/whatsapp"
  IMMEDIATE_DELIVERY: "true"
  SCHEDULED_DELIVERY_ENABLED: "true"
  DELIVERY_TRACKING_ENABLED: "true"
  OPEN_TRACKING_ENABLED: "true"
  CLICK_TRACKING_ENABLED: "true"

  # ================================================================
  # FORECASTING SETTINGS
  # ================================================================
  MAX_FORECAST_DAYS: "30"
  MIN_HISTORICAL_DAYS: "60"
  PREDICTION_CONFIDENCE_THRESHOLD: "0.8"
  PREDICTION_CACHE_TTL_HOURS: "6"
  FORECAST_BATCH_SIZE: "100"

  # ================================================================
  # BUSINESS RULES
  # ================================================================
  WEEKEND_ADJUSTMENT_FACTOR: "0.8"
  HOLIDAY_ADJUSTMENT_FACTOR: "0.5"
  TEMPERATURE_THRESHOLD_COLD: "10.0"
  TEMPERATURE_THRESHOLD_HOT: "30.0"
  RAIN_IMPACT_FACTOR: "0.7"
  HIGH_DEMAND_THRESHOLD: "1.5"
  LOW_DEMAND_THRESHOLD: "0.5"
  STOCKOUT_RISK_THRESHOLD: "0.9"

  # ================================================================
  # CACHE SETTINGS
  # ================================================================
  REDIS_TLS_ENABLED: "true"
  REDIS_MAX_MEMORY: "512mb"
  REDIS_MAX_CONNECTIONS: "50"
  REDIS_DB: "1"
  WEATHER_CACHE_TTL_HOURS: "1"
  TRAFFIC_CACHE_TTL_HOURS: "1"

  # ================================================================
  # FRONTEND CONFIGURATION
  # ================================================================
  VITE_APP_TITLE: "PanIA Dashboard"
  VITE_APP_VERSION: "1.0.0"
  VITE_API_URL: "/api"
  VITE_ENVIRONMENT: "production"

  # Pilot Program Configuration
  VITE_PILOT_MODE_ENABLED: "true"
  VITE_PILOT_COUPON_CODE: "PILOT2025"
  VITE_PILOT_TRIAL_MONTHS: "3"
  VITE_STRIPE_PUBLISHABLE_KEY: "pk_test_your_stripe_publishable_key_here"

  # ================================================================
  # LOCATION SETTINGS (Nominatim Geocoding)
  # ================================================================
  NOMINATIM_SERVICE_URL: "http://nominatim-service:8080"
  NOMINATIM_PBF_URL: "http://download.geofabrik.de/europe/spain-latest.osm.pbf"
  NOMINATIM_MEMORY_LIMIT: "8G"
  NOMINATIM_CPU_LIMIT: "4"

  # ================================================================
  # DISTRIBUTED TRACING (Jaeger/OpenTelemetry)
  # ================================================================
  JAEGER_COLLECTOR_ENDPOINT: "http://jaeger-collector.monitoring:4317"
  JAEGER_AGENT_HOST: "jaeger-agent.monitoring"
  JAEGER_AGENT_PORT: "6831"
  OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger-collector.monitoring:4317"
  OTEL_SERVICE_NAME: "bakery-ia"

  # ================================================================
 # REPLENISHMENT PLANNING SETTINGS
  # ================================================================
  REPLENISHMENT_PROJECTION_HORIZON_DAYS: "7"
  REPLENISHMENT_SERVICE_LEVEL: "0.95"
  REPLENISHMENT_BUFFER_DAYS: "1"

  # Safety Stock
  SAFETY_STOCK_SERVICE_LEVEL: "0.95"
  SAFETY_STOCK_METHOD: "statistical"

  # MOQ
  MOQ_CONSOLIDATION_WINDOW_DAYS: "7"
  MOQ_ALLOW_EARLY_ORDERING: "true"

  # Supplier Selection
  SUPPLIER_PRICE_WEIGHT: "0.40"
  SUPPLIER_LEAD_TIME_WEIGHT: "0.20"
  SUPPLIER_QUALITY_WEIGHT: "0.20"
  SUPPLIER_RELIABILITY_WEIGHT: "0.20"
  SUPPLIER_DIVERSIFICATION_THRESHOLD: "1000"
  SUPPLIER_MAX_SINGLE_PERCENTAGE: "0.70"

  # Circuit Breakers
  CIRCUIT_BREAKER_FAILURE_THRESHOLD: "5"
  CIRCUIT_BREAKER_TIMEOUT_DURATION: "60"
  CIRCUIT_BREAKER_SUCCESS_THRESHOLD: "2"

  # Saga
  SAGA_TIMEOUT_SECONDS: "600"
  SAGA_ENABLE_COMPENSATION: "true"

  # ================================================================
  # EXTERNAL DATA SERVICE V2 SETTINGS
  # ================================================================
  EXTERNAL_ENABLED_CITIES: "madrid"
  EXTERNAL_RETENTION_MONTHS: "6"  # Reduced from 24 to avoid memory issues during init
  EXTERNAL_CACHE_TTL_DAYS: "7"
  EXTERNAL_REDIS_URL: "rediss://redis-service:6379/0?ssl_cert_reqs=none"
