version: '3.8'

services:
  # RealCV Web Application
  realcv-web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: realcv-web
    ports:
      - "5000:8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ConnectionStrings__DefaultConnection=Server=sqlserver;Database=RealCV;User Id=sa;Password=TrueCV_P@ssw0rd!;TrustServerCertificate=True;
      - ConnectionStrings__HangfireConnection=Server=sqlserver;Database=RealCV_Hangfire;User Id=sa;Password=TrueCV_P@ssw0rd!;TrustServerCertificate=True;
      - AzureBlob__ConnectionString=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;
      - AzureBlob__ContainerName=cv-uploads
      - CompaniesHouse__BaseUrl=https://api.company-information.service.gov.uk
      - CompaniesHouse__ApiKey=${COMPANIES_HOUSE_API_KEY:-}
      - Anthropic__ApiKey=${ANTHROPIC_API_KEY:-}
    depends_on:
      sqlserver:
        condition: service_healthy
      azurite:
        condition: service_started
    networks:
      - realcv-network
    restart: unless-stopped

  # SQL Server Database
  sqlserver:
    image: mcr.microsoft.com/mssql/server:2022-latest
    container_name: realcv-sqlserver
    ports:
      - "1433:1433"
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=TrueCV_P@ssw0rd!
      - MSSQL_PID=Developer
    volumes:
      - sqlserver-data:/var/opt/mssql
    networks:
      - realcv-network
    healthcheck:
      test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "TrueCV_P@ssw0rd!" -C -Q "SELECT 1" || exit 1
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    restart: unless-stopped

  # Azure Storage Emulator (Azurite)
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite:latest
    container_name: realcv-azurite
    ports:
      - "10000:10000"  # Blob service
      - "10001:10001"  # Queue service
      - "10002:10002"  # Table service
    volumes:
      - azurite-data:/data
    command: "azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 --location /data --debug /data/debug.log"
    networks:
      - realcv-network
    restart: unless-stopped

  # Database initialization (runs migrations)
  db-init:
    build:
      context: .
      dockerfile: Dockerfile.migrations
    container_name: realcv-db-init
    environment:
      - ConnectionStrings__DefaultConnection=Server=sqlserver;Database=RealCV;User Id=sa;Password=TrueCV_P@ssw0rd!;TrustServerCertificate=True;
    depends_on:
      sqlserver:
        condition: service_healthy
    networks:
      - realcv-network
    restart: "no"

networks:
  realcv-network:
    driver: bridge

volumes:
  sqlserver-data:
  azurite-data:
