services:
  # Backend API
  - type: web
    name: ejarad-backend
    runtime: node
    plan: free
    buildCommand: cd backend && npm install
    startCommand: cd backend && npm start
    envVars:
      - key: NODE_ENV
        value: production
      - key: PORT
        value: 10000
      - key: DB_HOST
        fromDatabase:
          name: ejarad-mysql
          property: host
      - key: DB_PORT
        fromDatabase:
          name: ejarad-mysql
          property: port
      - key: DB_USER
        fromDatabase:
          name: ejarad-mysql
          property: user
      - key: DB_PASSWORD
        fromDatabase:
          name: ejarad-mysql
          property: password
      - key: DB_NAME
        fromDatabase:
          name: ejarad-mysql
          property: database
      - key: JWT_SECRET
        generateValue: true
      - key: FRONTEND_URL
        value: https://ejarad-frontend.onrender.com

  # Frontend React
  - type: static
    name: ejarad-frontend
    runtime: static
    plan: free
    buildCommand: cd frontend && npm install && npm run build
    staticPublishPath: ./frontend/build
    envVars:
      - key: REACT_APP_API_URL
        value: https://ejarad-backend.onrender.com/api

databases:
  - name: ejarad-mysql
    databaseName: ejarad_db
    user: ejarad_user
    plan: free
    ipAllowList: []