import os
from typing import Optional

# Load .env file manually from project root
from dotenv import load_dotenv
from pydantic_settings import BaseSettings

# Find and load .env file
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(current_dir)  # Go up one level from shared/
env_path = os.path.join(project_root, ".env")

if os.path.exists(env_path):
    load_dotenv(env_path)
    print(f"✅ Loaded .env from: {env_path}")
else:
    print(f"⚠️  .env not found at: {env_path}")


class Settings(BaseSettings):
    # Database
    DATABASE_URL: str = (
        "postgresql+asyncpg://admin:password@localhost:5432/women_safety"
    )

    # Redis
    REDIS_URL: str = "redis://localhost:6379/0"

    # Kafka
    KAFKA_BOOTSTRAP_SERVERS: str = "localhost:9092"

    # JWT
    SECRET_KEY: str = "your-secret-key-change-in-production"
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30

    # App
    APP_NAME: str = "Women Safety App"
    DEBUG: bool = True
    API_V1_STR: str = "/api/v1"

    # External Services
    FCM_SERVER_KEY: Optional[str] = None
    
    # FatSecret API для данных о питании
    FATSECRET_CLIENT_ID: str = "56342dd56fc74b26afb49d65b8f84c16"
    FATSECRET_CLIENT_SECRET: str = "fae178f189dc44ddb368cabe9069c0e3"
    FATSECRET_CUSTOMER_KEY: Optional[str] = None  # Исправляем опечатку в имени параметра

    # Security
    CORS_ORIGINS: list = ["*"]  # Change in production

    # Location
    MAX_EMERGENCY_RADIUS_KM: float = 1.0

    class Config:
        env_file = ".env"


settings = Settings()
