version: '3.8'

services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-shiftplan_db_dev}
      POSTGRES_USER: ${POSTGRES_USER:-shiftplan_user}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-shiftplan_dev_password_123}
    volumes:
      - postgres_dev_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-shiftplan_user} -d ${POSTGRES_DB:-shiftplan_db_dev}"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    command: >
      sh -c "python manage.py makemigrations --noinput &&
             python manage.py migrate --noinput &&
             python manage.py seed_data &&
             python manage.py runserver 0.0.0.0:8000"
    environment:
      SECRET_KEY: ${SECRET_KEY:-dev-secret-key-shiftplan}
      DEBUG: "True"
      ALLOWED_HOSTS: "*"
      POSTGRES_DB: ${POSTGRES_DB:-shiftplan_db_dev}
      POSTGRES_USER: ${POSTGRES_USER:-shiftplan_user}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-shiftplan_dev_password_123}
      POSTGRES_HOST: db
      POSTGRES_PORT: "5432"
    volumes:
      - ./backend:/app
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8000:8000"
    restart: unless-stopped

  frontend:
    image: node:20-alpine
    working_dir: /app
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0 --port 3000"
    volumes:
      - ./frontend:/app
    ports:
      - "3000:3000"
    depends_on:
      - backend
    restart: unless-stopped

volumes:
  postgres_dev_data:
