services:
  mysql:
    image: mysql:8.0
    container_name: billcare-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: billcare
      MYSQL_USER: billcare
      MYSQL_PASSWORD: billcare
    ports:
      - "3308:3306"
    volumes:
      - billcare_mysql:/var/lib/mysql
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 20s

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: billcare-backend
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/billcare?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul&characterEncoding=UTF-8
      SPRING_DATASOURCE_USERNAME: billcare
      SPRING_DATASOURCE_PASSWORD: billcare
      APP_CORS_ORIGINS: http://localhost:82,http://127.0.0.1:82,http://localhost:5174
      APP_UPLOAD_DIR: /app/storage/uploads
    volumes:
      - billcare_uploads:/app/storage/uploads
    ports:
      - "8082:8080"
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8080/api/health"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 40s

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: billcare-frontend
    depends_on:
      backend:
        condition: service_healthy
    ports:
      - "82:80"

volumes:
  billcare_mysql:
  billcare_uploads:
