# APAC Tenants Summary Task

Handler: `summary_function.lambda_handler`

This daily Lambda reads the APAC target database and sends one Feishu card with
accurate aggregate totals plus up to 10 detail rows for each section:

- P0 tenants, including Sales owner;
- P1 tenants, including Sales owner;
- HubSpot Target Accounts, including match method and Sales owner;
- APAC tenants with successful import events in the last seven days.

Active tenant sections use the same stock scope as the Dispatcher: active,
external, `sales_force_region = 'APAC'`, not JP, and excluding plans
`free_trial`, `new_user`, and `closing`. The aggregate previous-day signup,
non-individual signup, and AI-related signup counts use
`country_region = 'APAC'`, exclude JP, and are selected by `created_at`; they do
not depend on mutable `source_type`. Non-individual includes only the recognized
company and institution categories; `individual`, `unknown`, empty, and
unrecognized classifications are excluded.

Previous-day signup boundaries use CST natural days. Summary reads
`apac_active_tenants` only and intentionally excludes `apac_sales_owned_tenants`.

The Summary does not call OpenAI or calculate scores. Scoring is owned by
`APAC-Tenants-Scoring-Task`.

`tenant_avg_qps = NULL` is rendered as `N/A`, while a measured zero is rendered
as `0`.

## Configuration

Required:

- `TARGET_DATABASE_URL`, or the `TARGET_DB_*` variables;
- `FEISHU_WEBHOOK_URL`, supplied through a secret reference rather than stored
  in source control.

Optional:

- `TARGET_TIDB_SSL_CA_PATH` or `TIDB_SSL_CA_PATH`;
- `IMPORT_EVENT_COUNT_TABLE` (default `apac_tenant_events`);
- `SUMMARY_SECTION_LIMIT` (default 10).

Weekly Metrics and Summary should reference the same APAC Feishu webhook
secret. The role needs only CloudWatch Logs and read access to its secret; the
database account only needs read access to the APAC reporting tables.
