services:
  # Backend API Service
  - type: web
    name: pos-api
    runtime: node
    plan: free
    buildCommand: npm install && npm run generate -w packages/database && npm run build -w packages/api
    startCommand: npm run start -w packages/api
    envVars:
      - key: NODE_ENV
        value: production
      - key: DATABASE_URL
        fromDatabase:
          name: pos-db
          property: connectionString
      - key: JWT_SECRET
        generateValue: true

  # Admin Dashboard (Static Site)
  - type: static
    name: pos-admin
    runtime: static
    buildCommand: npm install && npm run build -w apps/admin
    publishDir: apps/admin/dist
    envVars:
      - key: VITE_API_URL
        fromService:
          type: web
          name: pos-api
          property: url

  # Cashier App (Static Site)
  - type: static
    name: pos-cashier
    runtime: static
    buildCommand: npm install && npm run build -w apps/cashier
    publishDir: apps/cashier/dist
    envVars:
      - key: VITE_API_URL
        fromService:
          type: web
          name: pos-api
          property: url

databases:
  - name: pos-db
    plan: free
    databaseName: pos_system
    user: pos_user

version: "1"
