services:

  # ── PostgreSQL ───────────────────────────────────────────────────────────────
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: miccheck
      POSTGRES_USER: miccheck
      POSTGRES_PASSWORD: password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U miccheck -d miccheck"]
      interval: 5s
      timeout: 5s
      retries: 10

  # ── .NET API ─────────────────────────────────────────────────────────────────
  api:
    build:
      context: .
      dockerfile: src/api/MicCheck.Api/Dockerfile
    ports:
      - "8080:8080"
    volumes:
      - ./src/api/MicCheck.Api/publish:/app
    environment:
      ASPNETCORE_ENVIRONMENT: Development
      ASPNETCORE_URLS: http://+:8080
      ConnectionStrings__DefaultConnection: "Host=db;Database=miccheck;Username=miccheck;Password=password"
      Jwt__SecretKey: "miccheck-dev-secret-key-change-in-production!!"
      Jwt__Issuer: MicCheck
      Jwt__Audience: MicCheck
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost:8080/api/v1/health 2>/dev/null || exit 0"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 20s

  # ── Vue Admin Site (nginx) ───────────────────────────────────────────────────
  admin:
    build:
      context: src/admin
      dockerfile: Dockerfile
    ports:
      - "3000:80"
    volumes:
      - ./src/admin/dist:/usr/share/nginx/html
    depends_on:
      api:
        condition: service_started

volumes:
  postgres_data:
