services:
  app:
    container_name: UniVerse
    build:
      context: ./backend
      dockerfile: Dockerfile
    restart: always
    ports:
      - "8088:8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
      
      - AzureAd:Instance=${AzureAd_Instance:-https://login.microsoftonline.com/}
      - AzureAd:TenantId=${AzureAd_TenantId:-sfedu.ru}
      - AzureAd:ClientId=${AzureAd_ClientId}
      - AzureAd:ClientSecret=${AzureAd_ClientSecret}
      - AzureAd:Domain=${AzureAd_Domain:-sfedu.onmicrosoft.com}
      - AzureAd:CallbackPath=${AzureAd_CallbackPath:-/signin-oidc}
      - AzureAd:RedirectUri=${AzureAd_RedirectUri:-http://localhost:8088/api/v1/auth/callback/microsoft}
      - AzureAd:PostLoginRedirectUri=${AzureAd_PostLoginRedirectUri:-}

      - Jwt:Secret=${JWT_SECRET}
      - Jwt:Issuer=${JWT_ISSUER:-UniVerse}
      - Jwt:Audience=${JWT_AUDIENCE:-UniVerse}
      - Jwt:AccessTokenExpirationMinutes=${JWT_EXPIRE_DAYS:-30}
      - Jwt:RefreshTokenExpirationDays=${JWT_EXPIRE_DAYS:-30}

      - Cors:Origins=${CORS_ALLOWED_ORIGINS:-http://localhost:3000}

      - Llm:BaseUrl=${LLM_BASE_URL}
      - Llm:ApiKey=${LLM_API_KEY}
      - Llm:Model=${LLM_MODEL}

      - ModeusApi:BaseUrl=${MODEUS_API_BASE_URL}
      - ModeusApi:ApiKey=${MODEUS_API_KEY}

      - Email:Smtp:Host=${EMAIL_SMTP_HOST}
      - Email:Smtp:Port=${EMAIL_SMTP_PORT:-587}
      - Email:Smtp:EnableSsl=${EMAIL_SMTP_ENABLE_SSL:-true}
      - Email:Smtp:UserName=${EMAIL_SMTP_USERNAME}
      - Email:Smtp:Password=${EMAIL_SMTP_PASSWORD}
      - Email:Smtp:FromAddress=${EMAIL_SMTP_FROM_ADDRESS:-no-reply@universe.local}
      - Email:Smtp:FromName=${EMAIL_SMTP_FROM_NAME:-UniVerse}
      - ConnectionStrings:DefaultConnection=Host=db;Port=5432;Database=${POSTGRES_DATABASE};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}

  db:
    image: postgres:18-alpine
    restart: always
    ports:
      - "5432"
    volumes:
      - database_data:/var/lib/postgresql
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DATABASE}
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}" ]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "80"
    restart: unless-stopped
