# ─────────────────────────────────────────────────────────────────────────────
# DigitalOcean Functions — scheduled cron for Property Management Network.
#
# App Platform has no native cron, so the two daily jobs are driven by DO
# Functions scheduler triggers that call the app's CRON_SECRET-protected
# endpoints. Deploy separately from the App Platform app:
#
#   doctl serverless deploy functions --env functions/.env
#
# Create functions/.env (gitignored) with:
#   APP_BASE_URL=https://<your-app-url>      # no trailing slash
#   CRON_SECRET=<same value as the app's CRON_SECRET>
# ─────────────────────────────────────────────────────────────────────────────
parameters: {}
packages:
  - name: cron
    functions:
      - name: run
        runtime: 'nodejs:18'
        web: false
        environment:
          APP_BASE_URL: ${APP_BASE_URL}
          CRON_SECRET: ${CRON_SECRET}
triggers:
  # Rent reminders, overdue marking, 60/30/7-day lease-expiry emails — 09:00 UTC.
  - name: daily
    sourceType: scheduler
    sourceDetails:
      cron: '0 9 * * *'
      withBody:
        job: daily
    function: cron/run
  # Late fees (5% after the grace period) — 08:00 UTC.
  - name: late-fees
    sourceType: scheduler
    sourceDetails:
      cron: '0 8 * * *'
      withBody:
        job: late-fees
    function: cron/run
  # Automated follow-ups for all users with active rules — 10:00 UTC.
  - name: follow-ups
    sourceType: scheduler
    sourceDetails:
      cron: '0 10 * * *'
      withBody:
        job: follow-ups
    function: cron/run
  # Outbound webhook delivery retries — every 5 minutes.
  - name: webhooks
    sourceType: scheduler
    sourceDetails:
      cron: '*/5 * * * *'
      withBody:
        job: webhooks
    function: cron/run
  # GDPR: execute account deletions whose 30-day grace period elapsed — 07:00 UTC.
  - name: gdpr
    sourceType: scheduler
    sourceDetails:
      cron: '0 7 * * *'
      withBody:
        job: gdpr
    function: cron/run
