services:
  backend-dev:
    build:
      context: ../backend
      dockerfile: ../docker/Dockerfile.backend.dev
    container_name: bamort-backend-dev
    ports:
      - "8180:8180"
    environment:
      - GO_ENV=development
      - CGO_ENABLED=1
      - DATABASE_TYPE=${DATABASE_TYPE:-mysql}
      - DATABASE_URL=${DATABASE_URL:-${MARIADB_USER:-bamort}:${MARIADB_PASSWORD:-secure_user_password}@tcp(mariadb-dev:3306)/${MARIADB_DATABASE:-bamort}?charset=utf8mb4&parseTime=True&loc=Local}
      - API_PORT=${API_PORT:-8180}
      - TEMPLATES_DIR=${TEMPLATES_DIR:-./templatesx}
      - EXPORT_TEMP_DIR=${EXPORT_TEMP_DIR:-./export_tempx}
      - GIT_COMMIT=${GIT_COMMIT:-unknown}
    depends_on:
      mariadb-dev:
        condition: service_healthy
    working_dir: /app
    # Restart if Go code changes cause crash
    restart: unless-stopped
    volumes:
      - ../backend:/app
      - go-mod-cache:/go/pkg/mod

  frontend-dev:
    build:
      context: ../frontend
      dockerfile: ../docker/Dockerfile.frontend.dev
    container_name: bamort-frontend-dev
    ports:
      - "5173:5173"  # Vite dev server port
    environment:
      - NODE_ENV=development
      - VITE_API_URL=${API_URL:-http://192.168.0.1:8180}
      - VITE_BASE_URL=${BASE_URL:-http://bamort.trokan.de}
      - VITE_API_PORT=${API_PORT:-8180}
    depends_on:
      - backend-dev
    restart: unless-stopped
    volumes:
      - ../frontend:/app
      - /app/node_modules  # Prevent overwriting node_modules

  mariadb-dev:
    image: mariadb:11.4
    container_name: bamort-mariadb-dev
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-secure_root_password}
      MARIADB_DATABASE: ${MARIADB_DATABASE:-bamort}
      MARIADB_USER: ${MARIADB_USER:-bamort}
      MARIADB_PASSWORD: ${MARIADB_PASSWORD:-secure_user_password}
      MARIADB_CHARSET: utf8mb4
      MARIADB_COLLATION: utf8mb4_unicode_ci
    volumes:
      - ./bamort-db-dev:/var/lib/mysql
      - ./init-db:/docker-entrypoint-initdb.d
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      start_period: 10s
      timeout: 5s
      retries: 3

  phpmyadmin-dev:
    image: phpmyadmin/phpmyadmin:5.2
    container_name: bamort-phpmyadmin-dev
    restart: unless-stopped
    ports:
      - "8081:80"
    environment:
      PMA_HOST: mariadb-dev
      PMA_PORT: 3306
      PMA_USER: root
      PMA_PASSWORD: ${MARIADB_ROOT_PASSWORD:-secure_root_password}
      MYSQL_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-secure_root_password}
      PMA_ARBITRARY: 1
    depends_on:
      mariadb-dev:
        condition: service_healthy

volumes:
  go-mod-cache:
