{"openapi":"3.1.0","info":{"title":"Alancorr Balance API","version":"1.0.0","description":"Backend del asistente Fina (chat, OCR, WhatsApp, config, proactive crons). Cloudflare Worker en `app.alancorr.com`. Auth: Clerk Bearer JWT salvo endpoints públicos (`/api/health`, `GET /api/whatsapp-webhook`)."},"servers":[{"url":"https://app.alancorr.com","description":"production"},{"url":"http://localhost:8787","description":"local dev"}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Clerk session JWT. Frontend obtains it via `window.Clerk.session.getToken()`."},"metaWebhookHmac":{"type":"apiKey","in":"header","name":"X-Hub-Signature-256","description":"HMAC-SHA256 of the raw request body, keyed with `META_APP_SECRET`. Format: `sha256=<hex>`. Required only on POST `/api/whatsapp-webhook`."},"cronSecret":{"type":"apiKey","in":"header","name":"X-Cron-Secret","description":"Shared secret matching `CRON_SECRET`. Used by Cloudflare cron triggers to authorize internal endpoints."},"svixSignature":{"type":"apiKey","in":"header","name":"svix-signature","description":"Firma Svix (`v1,<base64>`) sobre `svix-id.svix-timestamp.body`, keyed con `RESEND_MP_WEBHOOK_SECRET`. La mandan los webhooks de Resend (bandeja Mercado Pago, #513)."},"opsToken":{"type":"apiKey","in":"header","name":"X-Ops-Token","description":"Token de operaciones (`MP_OPS_TOKEN`) para los endpoints admin de la bandeja Mercado Pago (#513). Solo ops internas — no lo usa la app."},"reportToken":{"type":"apiKey","in":"query","name":"token","description":"HMAC-signed token (HMAC-SHA256 over `FINA_COOKIE_SECRET`) carrying `{familyId, yearMonth, exp}`. Used by `/api/reports/render/*` (query `secret`) and `/api/reports/monthly/{token}` (path). The token IS the auth — no Bearer required."}},"schemas":{"HealthResponse":{"type":"object","properties":{"ok":{"type":"boolean"},"timestamp":{"type":"string","format":"date-time"},"environment":{"type":"string"},"checks":{"type":"object","properties":{"db":{"$ref":"#/components/schemas/ProbeResult"},"openai":{"$ref":"#/components/schemas/ProbeResult"},"kv":{"$ref":"#/components/schemas/ProbeResult"},"vectorize":{"$ref":"#/components/schemas/ProbeResult"},"aiSearch":{"$ref":"#/components/schemas/ProbeResult"},"r2":{"$ref":"#/components/schemas/ProbeResult"},"queue":{"$ref":"#/components/schemas/ProbeResult"}},"required":["db","openai","kv","vectorize","aiSearch","r2","queue"]}},"required":["ok","timestamp"]},"ProbeResult":{"type":"object","properties":{"ok":{"type":"boolean"},"latencyMs":{"type":"integer","minimum":0},"note":{"type":"string"},"error":{"type":"string"}},"required":["ok"]},"SignoutResponse":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]},"device_revoked":{"type":"boolean"}},"required":["ok","device_revoked"]},"AgentOutput":{"type":"object","properties":{"text":{"type":"string"},"toolsExecuted":{"type":"array","items":{"type":"string"}},"tokensInput":{"type":"integer","minimum":0},"tokensOutput":{"type":"integer","minimum":0},"model":{"type":"string"},"conversationId":{"type":"string","format":"uuid"},"cacheHit":{"type":"boolean"},"attachments":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["image"]},"url":{"type":"string","format":"uri"},"caption":{"type":"string"}},"required":["type","url"]},"description":"Optional media attachments produced during the turn (currently only `render_chart` PNG URLs)."}},"required":["text","toolsExecuted","tokensInput","tokensOutput","model","conversationId"]},"Error":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"AgentRequest":{"type":"object","properties":{"message":{"type":"string","minLength":1,"maxLength":10000,"description":"Mensaje del usuario. Cap de 10 KB para evitar DoS y costos OpenAI imprevistos.","example":"¿cuánto gasté en comida este mes?"},"conversationId":{"type":"string","description":"UUID of an existing `ai_conversations` row. Empty string or omitted → the worker creates a new conversation and returns its id in the response / `ready` SSE event."},"stream":{"type":"boolean","description":"When `true`, response is `text/event-stream` (SSE) instead of JSON. Each event is a JSON chunk of the partial AgentOutput."},"imageBase64":{"type":"string","description":"Optional image (data URL) for vision tools."}},"required":["message"]},"AgentSettings":{"type":"object","properties":{"preferredModel":{"type":"string","example":"openai/gpt-5.4-mini"},"finaEnabled":{"type":"boolean"},"proactiveAlerts":{"type":"boolean"}},"required":["preferredModel","finaEnabled","proactiveAlerts"]},"AgentSettingsPatch":{"type":"object","properties":{"preferredModel":{"type":"string"},"finaEnabled":{"type":"boolean"},"proactiveAlerts":{"type":"boolean"}}},"PushResponse":{"type":"object","properties":{"ok":{"type":"boolean"},"sent":{"type":"integer"},"failed":{"type":"integer"},"pruned":{"type":"integer"},"skipped":{"type":"string"}},"required":["ok","sent","failed","pruned"]},"PushRequest":{"type":"object","properties":{"profileId":{"type":"string","format":"uuid"},"title":{"type":"string","minLength":1},"body":{"type":"string","minLength":1},"url":{"type":"string","format":"uri"}},"required":["profileId","title","body"]},"ReceiptOcrResult":{"type":"object","properties":{"cached":{"type":"boolean"},"merchant":{"type":"string","nullable":true},"total":{"type":"number","nullable":true},"date":{"type":"string","nullable":true,"example":"2026-04-29"},"currency":{"type":"string","nullable":true,"example":"ARS"},"items":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"qty":{"type":"number"},"price":{"type":"number"}},"required":["name","qty","price"]}},"notes":{"type":"string","nullable":true}},"required":["cached","merchant","total","date","currency","items","notes"]},"ReceiptOcrRequest":{"type":"object","properties":{"imageBase64":{"type":"string","minLength":1,"description":"Data URL or raw base64 of the receipt image.","example":"data:image/jpeg;base64,/9j/4AAQ..."},"sha256":{"type":"string","description":"Pre-computed SHA-256 of the image (skips re-hash on the server)."}},"required":["imageBase64"]},"PlacesAutocompleteResponse":{"type":"object","properties":{"suggestions":{"type":"array","items":{"$ref":"#/components/schemas/PlaceSuggestion"}}},"required":["suggestions"]},"PlaceSuggestion":{"type":"object","properties":{"placeId":{"type":"string"},"mainText":{"type":"string"},"secondaryText":{"type":"string"}},"required":["placeId","mainText","secondaryText"]},"PlacesDetailsResponse":{"type":"object","properties":{"details":{"$ref":"#/components/schemas/PlaceDetails"}},"required":["details"]},"PlaceDetails":{"type":"object","nullable":true,"properties":{"placeName":{"type":"string"},"latitude":{"type":"number"},"longitude":{"type":"number"},"formattedAddress":{"type":"string"}},"required":["placeName","latitude","longitude"]},"PlacesNearbyResponse":{"type":"object","properties":{"placeName":{"type":"string","nullable":true}},"required":["placeName"]},"Device":{"type":"object","properties":{"device_id":{"type":"string"},"label":{"type":"string","nullable":true},"user_agent":{"type":"string","nullable":true},"created_at":{"type":"string"},"last_seen":{"type":"string"},"is_current":{"type":"boolean"}},"required":["device_id","label","user_agent","created_at","last_seen","is_current"]},"Brand":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"canonical_name":{"type":"string"},"aliases":{"type":"array","items":{"type":"string"}},"default_category_id":{"type":"string","nullable":true,"format":"uuid"},"icon_slug":{"type":"string","nullable":true},"icon_kind":{"type":"string","enum":["iconify","emoji","favicon"]},"color_hex":{"type":"string","nullable":true},"is_dev_tool":{"type":"boolean"}},"required":["id","canonical_name","aliases","default_category_id","icon_slug","icon_kind","color_hex","is_dev_tool"]},"WeatherData":{"type":"object","properties":{"available":{"type":"boolean"},"temp":{"type":"number"},"feelsLike":{"type":"number"},"description":{"type":"string"},"city":{"type":"string"},"country":{"type":"string"},"humidity":{"type":"number"},"cached":{"type":"boolean"}}},"AiUsageAggregate":{"type":"object","properties":{"range":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"granularity":{"type":"string","enum":["hour","day"]}},"required":["from","to","granularity"]},"totals":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"}},"required":["cost_usd","requests","tokens_input","tokens_output"]},"by_profile":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"profile_id":{"type":"string"},"display_name":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","profile_id","display_name"]}},"by_model":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"model":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","model"]}},"by_endpoint":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"endpoint":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","endpoint"]}},"series":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"bucket":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","bucket"]}},"latency":{"type":"object","properties":{"p50_ms":{"type":"number","nullable":true},"p95_ms":{"type":"number","nullable":true},"histogram":{"type":"array","items":{"type":"object","properties":{"bucket":{"type":"string"},"count":{"type":"integer"}},"required":["bucket","count"]}}},"required":["p50_ms","p95_ms","histogram"]},"top_requests":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"created_at":{"type":"string"},"profile_id":{"type":"string"},"display_name":{"type":"string"},"model":{"type":"string"},"endpoint":{"type":"string"},"cost_usd":{"type":"number"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"execution_time_ms":{"type":"number","nullable":true}},"required":["id","created_at","profile_id","display_name","model","endpoint","cost_usd","tokens_input","tokens_output","execution_time_ms"]}},"projection":{"type":"object","properties":{"spent_so_far":{"type":"number"},"days_elapsed":{"type":"number"},"days_in_month":{"type":"number"},"linear_estimate":{"type":"number"},"ma7_estimate":{"type":"number"},"budget_usd":{"type":"number","nullable":true},"pct_of_budget":{"type":"number","nullable":true}},"required":["spent_so_far","days_elapsed","days_in_month","linear_estimate","ma7_estimate","budget_usd","pct_of_budget"]}},"required":["range","totals","by_profile","by_model","by_endpoint","series","latency","top_requests","projection"]},"AiProviderInfo":{"type":"object","properties":{"provider":{"type":"string"},"default_model":{"type":"string"},"gateway_enabled":{"type":"boolean"},"api_key_fingerprint":{"type":"string","nullable":true}},"required":["provider","default_model","gateway_enabled","api_key_fingerprint"]},"AiBudgetConfig":{"type":"object","nullable":true,"properties":{"family_id":{"type":"string","format":"uuid"},"monthly_budget_usd":{"type":"number","minimum":0},"alert_thresholds_pct":{"type":"array","items":{"type":"integer","minimum":1,"maximum":1000}},"channels":{"type":"array","items":{"type":"string","enum":["in_app","whatsapp"]}},"updated_at":{"type":"string","nullable":true}},"required":["family_id","monthly_budget_usd","alert_thresholds_pct","channels","updated_at"]},"AiBudgetUpdate":{"type":"object","properties":{"monthly_budget_usd":{"type":"number","minimum":0},"alert_thresholds_pct":{"type":"array","items":{"type":"integer","minimum":1,"maximum":1000},"default":[50,80,100]},"channels":{"type":"array","items":{"type":"string","enum":["in_app","whatsapp"]},"default":["in_app","whatsapp"]}},"required":["monthly_budget_usd"]},"DlqListResponse":{"type":"object","properties":{"items":{"type":"array","items":{"$ref":"#/components/schemas/DlqRow"}},"total":{"type":"integer"}},"required":["items","total"]},"DlqRow":{"type":"object","properties":{"id":{"type":"string"},"external_id":{"type":"string","nullable":true},"attempts":{"type":"integer","nullable":true},"error_message":{"type":"string","nullable":true},"created_at":{"type":"string"},"replayed_at":{"type":"string","nullable":true}},"required":["id","external_id","attempts","error_message","created_at","replayed_at"]},"DlqReplayResponse":{"type":"object","properties":{"id":{"type":"string"},"replayed_at":{"type":"string"},"enqueued":{"type":"boolean"},"external_id":{"type":"string","nullable":true},"idempotency_claim_dropped":{"type":"boolean"},"idempotency_error":{"type":"string","nullable":true}},"required":["id","replayed_at","enqueued","external_id","idempotency_claim_dropped","idempotency_error"]},"LearningRebuildResult":{"type":"object","properties":{"family_id":{"type":"string"},"merchant_patterns":{"type":"integer"},"temporal_patterns":{"type":"integer"},"recurring_predictions":{"type":"integer"},"context_addendum_chars":{"type":"integer"},"errors":{"type":"array","items":{"type":"string"}}},"required":["family_id","merchant_patterns","temporal_patterns","recurring_predictions","context_addendum_chars","errors"]},"LearningError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"VectorizeBackfillResult":{"type":"object","properties":{"family_id":{"type":"string"},"scanned":{"type":"integer"},"written":{"type":"integer"},"skipped":{"type":"integer"},"duration_ms":{"type":"integer"}},"required":["family_id","scanned","written","skipped","duration_ms"]},"VectorizeAdminError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"AdminStatsV2":{"type":"object","properties":{"meta":{"type":"object","properties":{"generatedAt":{"type":"string"},"rangeFrom":{"type":"string"},"rangeTo":{"type":"string"},"cachedFromKV":{"type":"boolean"},"sources":{"type":"object","properties":{"db":{"type":"string","enum":["ok","error"]},"workersAi":{"type":"string","enum":["ok","unavailable","error"]},"aiGateway":{"type":"string","enum":["ok","unavailable","error"]},"bindings":{"type":"string","enum":["ok","error"]}},"required":["db","workersAi","aiGateway","bindings"]}},"required":["generatedAt","rangeFrom","rangeTo","cachedFromKV","sources"]},"salud":{"type":"object","additionalProperties":{"nullable":true}},"agente":{"type":"object","additionalProperties":{"nullable":true}},"infra":{"type":"object","additionalProperties":{"nullable":true}},"negocio":{"type":"object","additionalProperties":{"nullable":true}},"costos":{"type":"object","additionalProperties":{"nullable":true}}},"required":["meta","salud","agente","infra","negocio","costos"]},"FinaSprintMetrics":{"type":"object","properties":{"bna_quote":{"type":"object","nullable":true,"properties":{"date":{"type":"string"},"sell":{"type":"number"},"buy":{"type":"number","nullable":true},"fetched_at":{"type":"string"}},"required":["date","sell","buy","fetched_at"]},"brands":{"type":"object","properties":{"total":{"type":"integer"},"dev_tools":{"type":"integer"},"tx_with_brand":{"type":"integer"},"tx_total_30d":{"type":"integer"},"brand_match_rate":{"type":"number"},"top_brands_30d":{"type":"array","items":{"type":"object","properties":{"canonical_name":{"type":"string"},"icon_slug":{"type":"string","nullable":true},"tx_count":{"type":"integer"},"total_ars":{"type":"number"}},"required":["canonical_name","icon_slug","tx_count","total_ars"]}}},"required":["total","dev_tools","tx_with_brand","tx_total_30d","brand_match_rate","top_brands_30d"]},"flags":{"type":"object","properties":{"essential_count":{"type":"integer"},"recurring_count":{"type":"integer"},"requires_review_count":{"type":"integer"},"possible_duplicate_count":{"type":"integer"},"with_payment_method":{"type":"integer"},"with_tags":{"type":"integer"},"tx_total_30d":{"type":"integer"}},"required":["essential_count","recurring_count","requires_review_count","possible_duplicate_count","with_payment_method","with_tags","tx_total_30d"]},"dev_stack":{"type":"object","properties":{"brands_active":{"type":"integer"},"total_usd_month":{"type":"number"},"total_ars_month":{"type":"number"},"month_key":{"type":"string"}},"required":["brands_active","total_usd_month","total_ars_month","month_key"]},"freelance":{"type":"object","nullable":true,"properties":{"usd_income":{"type":"number"},"usd_expense":{"type":"number"},"usd_net":{"type":"number"},"month_key":{"type":"string"}},"required":["usd_income","usd_expense","usd_net","month_key"]},"deductibles":{"type":"object","properties":{"ytd_count":{"type":"integer"},"ytd_total_ars":{"type":"number"},"ytd_total_usd":{"type":"number"},"projects":{"type":"array","items":{"type":"string"}}},"required":["ytd_count","ytd_total_ars","ytd_total_usd","projects"]},"audit":{"type":"object","properties":{"changes_7d":{"type":"integer"},"by_actor":{"type":"object","additionalProperties":{"type":"integer"}}},"required":["changes_7d","by_actor"]},"soft_deleted":{"type":"object","properties":{"count_30d":{"type":"integer"}},"required":["count_30d"]},"daily_intelligence":{"type":"object","nullable":true,"properties":{"last_score":{"type":"integer"},"last_date":{"type":"string"},"score_trend_7d":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string"},"score":{"type":"integer"}},"required":["date","score"]}}},"required":["last_score","last_date","score_trend_7d"]},"crons":{"type":"object","properties":{"proactive_logs_7d":{"type":"integer"},"last_proactive_run":{"type":"string","nullable":true},"forgotten_subs_logs_7d":{"type":"integer"},"predictions_logs_7d":{"type":"integer"},"daily_intel_logs_7d":{"type":"integer"}},"required":["proactive_logs_7d","last_proactive_run","forgotten_subs_logs_7d","predictions_logs_7d","daily_intel_logs_7d"]},"learning":{"type":"object","properties":{"merchant_patterns":{"type":"integer"},"temporal_patterns":{"type":"integer"},"recurring_predictions":{"type":"integer"},"family_context_cached":{"type":"boolean"}},"required":["merchant_patterns","temporal_patterns","recurring_predictions","family_context_cached"]},"forgotten_subs":{"type":"object","properties":{"pending_alerts":{"type":"integer"}},"required":["pending_alerts"]}},"required":["bna_quote","brands","flags","dev_stack","freelance","deductibles","audit","soft_deleted","daily_intelligence","crons","learning","forgotten_subs"]},"WhatsAppTemplatesStatus":{"type":"object","properties":{"wabaId":{"type":"string","nullable":true},"source":{"type":"string"},"hasManagementScope":{"type":"boolean"},"scopes":{"type":"array","items":{"type":"string"}},"templates":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppTemplate"}},"expected":{"type":"array","items":{"type":"string"}},"detail":{"type":"string","nullable":true}},"required":["wabaId","source","hasManagementScope","scopes","templates","expected","detail"]},"WhatsAppTemplate":{"type":"object","properties":{"name":{"type":"string"},"status":{"type":"string"},"category":{"type":"string"},"language":{"type":"string"}},"required":["name","status"]},"WhatsAppTemplatesError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"WhatsAppTemplatesSyncResponse":{"type":"object","properties":{"wabaId":{"type":"string"},"results":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppTemplateSyncResult"}}},"required":["wabaId","results"]},"WhatsAppTemplateSyncResult":{"type":"object","properties":{"name":{"type":"string"},"action":{"type":"string","enum":["created","exists","error"]},"status":{"type":"string","nullable":true},"detail":{"type":"string","nullable":true}},"required":["name","action","status","detail"]},"IntegrationProbeResult":{"type":"object","properties":{"id":{"type":"string"},"status":{"type":"string","enum":["ok","error","not_configured","not_implemented"]},"detail":{"type":"string","nullable":true}},"required":["id","status","detail"]},"IntegrationError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"GitHubSyncResult":{"type":"object","properties":{"fetched":{"type":"integer"},"inserted":{"type":"integer"},"skipped":{"type":"integer"},"repo":{"type":"string"}},"required":["fetched","inserted","skipped","repo"]},"GitHubError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"GitHubSyncRequest":{"type":"object","properties":{"owner":{"type":"string","minLength":1,"example":"Cristian-Alancay"},"repo":{"type":"string","minLength":1,"example":"alancorr-balance-cloudflare"},"since":{"type":"string","format":"date-time","description":"ISO8601 lower bound for commit date."},"per_page":{"type":"integer","minimum":1,"maximum":100,"example":30}}},"AdminRenderMonthlyOutput":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]},"download_url":{"type":"string","format":"uri"},"r2_key":{"type":"string"},"bytes":{"type":"integer","minimum":0,"exclusiveMinimum":true},"expires_at":{"type":"string","format":"date-time"}},"required":["ok","download_url","r2_key","bytes","expires_at"]},"AdminRenderMonthlyInput":{"type":"object","properties":{"family_id":{"type":"string","format":"uuid"},"year_month":{"type":"string","pattern":"^\\d{4}-\\d{2}$","example":"2026-04"}},"required":["family_id","year_month"]},"MeAiUsageAggregate":{"type":"object","properties":{"range":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"granularity":{"type":"string","enum":["hour","day"]}},"required":["from","to","granularity"]},"totals":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"}},"required":["cost_usd","requests","tokens_input","tokens_output"]},"by_model":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"model":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","model"]}},"by_endpoint":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"endpoint":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","endpoint"]}},"series":{"type":"array","items":{"type":"object","properties":{"cost_usd":{"type":"number"},"requests":{"type":"integer"},"tokens_input":{"type":"integer"},"tokens_output":{"type":"integer"},"bucket":{"type":"string"}},"required":["cost_usd","requests","tokens_input","tokens_output","bucket"]}},"latency":{"type":"object","properties":{"p50_ms":{"type":"number","nullable":true},"p95_ms":{"type":"number","nullable":true}},"required":["p50_ms","p95_ms"]},"projection":{"type":"object","properties":{"spent_so_far":{"type":"number"},"days_elapsed":{"type":"number"},"days_in_month":{"type":"number"},"linear_estimate":{"type":"number"},"ma7_estimate":{"type":"number"}},"required":["spent_so_far","days_elapsed","days_in_month","linear_estimate","ma7_estimate"]}},"required":["range","totals","by_model","by_endpoint","series","latency","projection"]},"UploadReceiptResponse":{"type":"object","properties":{"key":{"type":"string"},"url":{"type":"string"},"content_type":{"type":"string"},"size_bytes":{"type":"integer"}},"required":["key","url","content_type","size_bytes"]},"DeductibleRow":{"type":"object","properties":{"date":{"type":"string"},"category":{"type":"string","nullable":true},"brand":{"type":"string","nullable":true},"description":{"type":"string","nullable":true},"amount_native":{"type":"number"},"currency":{"type":"string"},"amount_ars":{"type":"number"},"payment_method":{"type":"string","nullable":true},"project":{"type":"string","nullable":true},"invoice_to":{"type":"string","nullable":true}},"required":["date","category","brand","description","amount_native","currency","amount_ars","payment_method","project","invoice_to"]},"TransactionAuditRow":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"transaction_id":{"type":"string","format":"uuid"},"field_name":{"type":"string"},"old_value":{"nullable":true},"new_value":{"nullable":true},"changed_by":{"type":"string","enum":["user","agent","system","cron"]},"reason":{"type":"string","nullable":true},"created_at":{"type":"string"}},"required":["id","transaction_id","field_name","changed_by","reason","created_at"]},"TransactionAttachmentRow":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"transaction_id":{"type":"string","format":"uuid"},"r2_key":{"type":"string"},"content_type":{"type":"string"},"caption":{"type":"string","nullable":true},"size_bytes":{"type":"integer","nullable":true},"created_at":{"type":"string"},"url":{"type":"string"}},"required":["id","transaction_id","r2_key","content_type","caption","size_bytes","created_at","url"]},"Transaction":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"profile_id":{"type":"string","nullable":true},"account_id":{"type":"string"},"category_id":{"type":"string","nullable":true},"type":{"type":"string"},"amount":{"type":"number"},"amount_ars":{"type":"number"},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"description":{"type":"string","nullable":true},"date":{"type":"string"},"notes":{"type":"string","nullable":true},"attachment_url":{"type":"string","nullable":true},"latitude":{"type":"number","nullable":true},"longitude":{"type":"number","nullable":true},"place_name":{"type":"string","nullable":true},"source":{"type":"string"},"brand_id":{"type":"string","nullable":true},"payment_method":{"type":"string","nullable":true},"is_essential":{"type":"boolean","nullable":true},"is_recurring":{"type":"boolean","nullable":true},"is_internal_transfer":{"type":"boolean"},"requires_review":{"type":"boolean"},"tags":{"type":"array","items":{"type":"string"}},"is_deductible":{"type":"boolean","nullable":true},"deductible_project":{"type":"string","nullable":true},"deductible_invoice_to":{"type":"string","nullable":true},"deleted_at":{"type":"string","nullable":true},"possible_duplicate":{"type":"boolean"},"time_known":{"type":"boolean"},"created_at":{"type":"string"},"updated_at":{"type":"string"},"accounts":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"type":{"type":"string","nullable":true},"currency":{"type":"string","nullable":true}},"required":["name"]},"categories":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"icon":{"type":"string","nullable":true}},"required":["name","icon"]},"profiles":{"type":"object","nullable":true,"properties":{"full_name":{"type":"string","nullable":true},"avatar_url":{"type":"string","nullable":true}},"required":["full_name","avatar_url"]},"brands":{"type":"object","nullable":true,"properties":{"canonical_name":{"type":"string"},"icon_slug":{"type":"string","nullable":true},"icon_kind":{"type":"string"},"color_hex":{"type":"string","nullable":true}},"required":["canonical_name","icon_slug","icon_kind","color_hex"]}},"required":["id","family_id","profile_id","account_id","category_id","type","amount","amount_ars","currency","exchange_rate","description","date","notes","attachment_url","latitude","longitude","place_name","source","brand_id","payment_method","is_essential","is_recurring","is_internal_transfer","requires_review","tags","is_deductible","deductible_project","deductible_invoice_to","deleted_at","possible_duplicate","time_known","created_at","updated_at"],"additionalProperties":{"nullable":true}},"TransactionsError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"CreateTransactionBody":{"type":"object","properties":{"profile_id":{"type":"string","nullable":true},"account_id":{"type":"string"},"category_id":{"type":"string","nullable":true},"type":{"type":"string","enum":["income","expense"]},"amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"amount_ars":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string","default":"ARS"},"exchange_rate":{"type":"number","nullable":true},"description":{"type":"string","nullable":true},"date":{"type":"string"},"notes":{"type":"string","nullable":true},"attachment_url":{"type":"string","nullable":true},"latitude":{"type":"number","nullable":true},"longitude":{"type":"number","nullable":true},"place_name":{"type":"string","nullable":true},"source":{"type":"string"},"is_internal_transfer":{"type":"boolean"},"is_deductible":{"type":"boolean","nullable":true},"deductible_project":{"type":"string","nullable":true},"deductible_invoice_to":{"type":"string","nullable":true}},"required":["account_id","type","amount","amount_ars","date"]},"UpdateTransactionBody":{"type":"object","properties":{"account_id":{"type":"string"},"category_id":{"type":"string","nullable":true},"type":{"type":"string","enum":["income","expense"]},"amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"amount_ars":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"description":{"type":"string","nullable":true},"date":{"type":"string"},"notes":{"type":"string","nullable":true},"attachment_url":{"type":"string","nullable":true},"latitude":{"type":"number","nullable":true},"longitude":{"type":"number","nullable":true},"place_name":{"type":"string","nullable":true},"is_deductible":{"type":"boolean","nullable":true},"deductible_project":{"type":"string","nullable":true},"deductible_invoice_to":{"type":"string","nullable":true}}},"TransactionItem":{"type":"object","properties":{"id":{"type":"string"},"transaction_id":{"type":"string"},"description":{"type":"string"},"quantity":{"type":"number","nullable":true},"unit_price":{"type":"number","nullable":true},"total_price":{"type":"number"},"source":{"type":"string"},"created_at":{"type":"string"}},"required":["id","transaction_id","description","quantity","unit_price","total_price","source","created_at"]},"CreateTransactionItemBody":{"type":"object","properties":{"description":{"type":"string","minLength":1},"quantity":{"type":"number","nullable":true},"unit_price":{"type":"number","nullable":true},"total_price":{"type":"number"},"source":{"type":"string"}},"required":["description","total_price"]},"MeAnalytics":{"type":"object","properties":{"period":{"type":"object","properties":{"key":{"type":"string","enum":["last_7_days","last_15_days","this_month","last_3_months","last_6_months","this_year","custom"]},"start":{"type":"string"},"end":{"type":"string"}},"required":["key","start","end"]},"previous":{"type":"object","properties":{"start":{"type":"string"},"end":{"type":"string"}},"required":["start","end"]},"totals":{"type":"object","properties":{"income":{"type":"number"},"expense":{"type":"number"},"net":{"type":"number"},"tx_count":{"type":"integer"}},"required":["income","expense","net","tx_count"]},"previous_totals":{"type":"object","properties":{"income":{"type":"number"},"expense":{"type":"number"},"net":{"type":"number"}},"required":["income","expense","net"]},"by_category":{"type":"array","items":{"type":"object","properties":{"category_id":{"type":"string","nullable":true},"name":{"type":"string","nullable":true},"icon":{"type":"string","nullable":true},"type":{"type":"string"},"total":{"type":"number"},"count":{"type":"integer"},"prev_total":{"type":"number"},"parent_id":{"type":"string","nullable":true},"parent_name":{"type":"string","nullable":true},"parent_icon":{"type":"string","nullable":true}},"required":["category_id","name","icon","type","total","count","prev_total","parent_id","parent_name","parent_icon"]}},"by_profile":{"type":"array","items":{"type":"object","properties":{"profile_id":{"type":"string","nullable":true},"full_name":{"type":"string"},"avatar_url":{"type":"string","nullable":true},"member_type":{"type":"string","nullable":true},"income":{"type":"number"},"expense":{"type":"number"},"count":{"type":"integer"}},"required":["profile_id","full_name","avatar_url","member_type","income","expense","count"]}},"series":{"type":"array","items":{"type":"object","properties":{"bucket":{"type":"string"},"income":{"type":"number"},"expense":{"type":"number"}},"required":["bucket","income","expense"]}},"top_movements":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"date":{"type":"string"},"description":{"type":"string","nullable":true},"amount_ars":{"type":"number"},"type":{"type":"string"},"category_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true}},"required":["id","date","description","amount_ars","type","category_id","profile_id"]}},"unconverted":{"type":"array","items":{"type":"object","properties":{"currency":{"type":"string"},"type":{"type":"string"},"count":{"type":"integer"},"amount_original":{"type":"number"}},"required":["currency","type","count","amount_original"]}}},"required":["period","previous","totals","previous_totals","by_category","by_profile","series","top_movements","unconverted"]},"AnalyticsError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"CreateTransferResponse":{"type":"object","properties":{"transfer_group_id":{"type":"string"},"expense_id":{"type":"string"},"income_id":{"type":"string"},"transactions":{"type":"array","items":{"$ref":"#/components/schemas/TransferLeg"}}},"required":["transfer_group_id","expense_id","income_id","transactions"]},"TransferLeg":{"type":"object","properties":{"id":{"type":"string"},"account_id":{"type":"string"},"profile_id":{"type":"string","nullable":true},"category_id":{"type":"string","nullable":true},"type":{"type":"string"},"amount":{"type":"number"},"amount_ars":{"type":"number"},"currency":{"type":"string"},"date":{"type":"string"},"description":{"type":"string","nullable":true},"is_internal_transfer":{"type":"boolean"}},"required":["id","account_id","profile_id","category_id","type","amount","amount_ars","currency","date","description","is_internal_transfer"],"additionalProperties":{"nullable":true}},"TransfersError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"CreateTransferBody":{"type":"object","properties":{"from_account_id":{"type":"string","minLength":1},"to_account_id":{"type":"string","minLength":1},"amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string","default":"ARS"},"amount_ars":{"type":"number","minimum":0,"exclusiveMinimum":true},"exchange_rate":{"type":"number","nullable":true,"minimum":0,"exclusiveMinimum":true},"date":{"type":"string"},"description":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true}},"required":["from_account_id","to_account_id","amount","date"]},"Account":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","format":"uuid"},"name":{"type":"string"},"type":{"type":"string"},"account_subtype":{"type":"string","nullable":true},"owner_type":{"type":"string"},"profile_id":{"type":"string","nullable":true,"format":"uuid"},"balance":{"type":"number"},"currency":{"type":"string"},"is_default":{"type":"boolean"},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","name","type","account_subtype","owner_type","profile_id","balance","currency","is_default","created_at","updated_at"]},"AccountInsert":{"type":"object","properties":{"name":{"type":"string","minLength":1},"type":{"type":"string","enum":["bank","cash","credit_card","mercado_pago","other"]},"owner_type":{"type":"string","enum":["profile","shared","house"]},"profile_id":{"type":"string","nullable":true,"format":"uuid"},"account_subtype":{"type":"string","nullable":true,"enum":["current","savings",null]},"balance":{"type":"number"},"currency":{"type":"string"}},"required":["name","type","owner_type"]},"AccountUpdate":{"type":"object","properties":{"name":{"type":"string","minLength":1},"type":{"type":"string","enum":["bank","cash","credit_card","mercado_pago","other"]},"owner_type":{"type":"string","enum":["profile","shared","house"]},"profile_id":{"type":"string","nullable":true,"format":"uuid"},"account_subtype":{"type":"string","nullable":true,"enum":["current","savings",null]},"balance":{"type":"number"},"currency":{"type":"string"}}},"AccountSetDefault":{"type":"object","properties":{"profile_id":{"type":"string","format":"uuid"},"currency":{"type":"string"},"make_default":{"type":"boolean"}},"required":["profile_id","currency","make_default"]},"BudgetRow":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","format":"uuid"},"category_id":{"type":"string","format":"uuid"},"month":{"type":"string"},"amount":{"type":"number"},"amount_ars":{"type":"number","nullable":true},"currency":{"type":"string"},"goal_description":{"type":"string","nullable":true},"created_at":{"type":"string"},"category":{"type":"object","nullable":true,"properties":{"name":{"type":"string"}},"required":["name"]}},"required":["id","family_id","category_id","month","amount","amount_ars","currency","goal_description","created_at","category"]},"Budget":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","format":"uuid"},"category_id":{"type":"string","format":"uuid"},"month":{"type":"string"},"amount":{"type":"number"},"amount_ars":{"type":"number","nullable":true},"currency":{"type":"string"},"goal_description":{"type":"string","nullable":true},"created_at":{"type":"string"}},"required":["id","family_id","category_id","month","amount","amount_ars","currency","goal_description","created_at"]},"BudgetStatusRow":{"type":"object","properties":{"id":{"type":"string","nullable":true},"budget_id":{"type":"string","nullable":true},"family_id":{"type":"string","nullable":true},"category_id":{"type":"string","nullable":true},"currency":{"type":"string","nullable":true},"amount":{"type":"number","nullable":true},"spent":{"type":"number","nullable":true},"pct_used":{"type":"number","nullable":true},"period_start":{"type":"string","nullable":true},"period_end":{"type":"string","nullable":true}},"required":["id","budget_id","family_id","category_id","currency","amount","spent","pct_used","period_start","period_end"]},"Category":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","nullable":true,"format":"uuid"},"name":{"type":"string"},"type":{"type":"string"},"icon":{"type":"string","nullable":true},"is_system":{"type":"boolean"},"created_at":{"type":"string"},"parent_id":{"type":"string","nullable":true,"format":"uuid"}},"required":["id","family_id","name","type","icon","is_system","created_at","parent_id"]},"CreateCategoryBody":{"type":"object","properties":{"name":{"type":"string","minLength":2,"maxLength":60},"type":{"type":"string","enum":["income","expense"]},"icon":{"type":"string","nullable":true,"maxLength":8},"parent_id":{"type":"string","nullable":true,"format":"uuid"}},"required":["name","type"]},"UpdateCategoryBody":{"type":"object","properties":{"name":{"type":"string","minLength":2,"maxLength":60},"icon":{"type":"string","nullable":true,"maxLength":8},"parent_id":{"type":"string","nullable":true,"format":"uuid"},"archived":{"type":"boolean"}}},"ScheduledIncomeRow":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"amount":{"type":"number"},"amount_ars":{"type":"number","nullable":true},"frequency":{"type":"string"},"day_of_month":{"type":"number","nullable":true},"next_due":{"type":"string","nullable":true},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"},"categories":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"icon":{"type":"string","nullable":true}},"required":["name","icon"]},"profiles":{"type":"object","nullable":true,"properties":{"full_name":{"type":"string","nullable":true}},"required":["full_name"]}},"required":["id","family_id","name","amount","amount_ars","frequency","day_of_month","next_due","currency","exchange_rate","category_id","account_id","profile_id","created_at","updated_at"]},"ScheduledExpenseRow":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"amount":{"type":"number"},"amount_ars":{"type":"number","nullable":true},"frequency":{"type":"string"},"next_due":{"type":"string","nullable":true},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"is_variable":{"type":"boolean","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"},"categories":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"icon":{"type":"string","nullable":true}},"required":["name","icon"]},"profiles":{"type":"object","nullable":true,"properties":{"full_name":{"type":"string","nullable":true}},"required":["full_name"]}},"required":["id","family_id","name","amount","amount_ars","frequency","next_due","currency","exchange_rate","category_id","account_id","profile_id","is_variable","created_at","updated_at"]},"InstallmentRow":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"total_amount":{"type":"number"},"total_amount_ars":{"type":"number"},"remaining_amount":{"type":"number"},"remaining_amount_ars":{"type":"number"},"installments_total":{"type":"number"},"installments_paid":{"type":"number"},"kind":{"type":"string","nullable":true},"next_due":{"type":"string","nullable":true},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"},"categories":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"icon":{"type":"string","nullable":true}},"required":["name","icon"]},"profiles":{"type":"object","nullable":true,"properties":{"full_name":{"type":"string","nullable":true}},"required":["full_name"]},"accounts":{"type":"object","nullable":true,"properties":{"name":{"type":"string"}},"required":["name"]}},"required":["id","family_id","name","total_amount","total_amount_ars","remaining_amount","remaining_amount_ars","installments_total","installments_paid","kind","next_due","currency","exchange_rate","category_id","account_id","profile_id","created_at","updated_at"]},"CommitmentScheduledPaymentRow":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"profile_id":{"type":"string","nullable":true},"schedule_id":{"type":"string","nullable":true},"installment_id":{"type":"string","nullable":true},"scheduled_income_id":{"type":"string","nullable":true},"transaction_id":{"type":"string","nullable":true},"period_month":{"type":"string"},"amount_ars":{"type":"number"},"paid_date":{"type":"string"},"notes":{"type":"string","nullable":true},"created_at":{"type":"string"}},"required":["id","family_id","profile_id","schedule_id","installment_id","scheduled_income_id","transaction_id","period_month","amount_ars","paid_date","notes","created_at"]},"ExternalDebtStatusRow":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"brand_id":{"type":"string"},"brand_name":{"type":"string"},"total_initial":{"type":"number"},"currency":{"type":"string"},"started_at":{"type":"string"},"description":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true},"total_paid":{"type":"number"},"remaining":{"type":"number"},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","brand_id","brand_name","total_initial","currency","started_at","description","notes","total_paid","remaining","created_at","updated_at"]},"CoachCommitmentVerdict":{"type":"object","properties":{"id":{"type":"string"},"rawText":{"type":"string"},"kind":{"type":"string","enum":["cut","reduce","limit","quit"]},"dimensionLabel":{"type":"string","nullable":true},"status":{"type":"string","enum":["active","met","broken","expired"]},"count":{"type":"number"},"sumArs":{"type":"number"},"daysSince":{"type":"number"},"keeping":{"type":"boolean"}},"required":["id","rawText","kind","dimensionLabel","status","count","sumArs","daysSince","keeping"]},"CoachBriefing":{"type":"object","properties":{"date":{"type":"string"},"narrative":{"type":"string"},"healthScore":{"type":"number","nullable":true},"generatedAt":{"type":"string","nullable":true}},"required":["date","narrative","healthScore","generatedAt"]},"CoachVigilanceSummary":{"type":"object","properties":{"baselines":{"type":"array","items":{"$ref":"#/components/schemas/CoachBaselineSummary"}},"alerts":{"type":"array","items":{"$ref":"#/components/schemas/CoachVigilanceAlert"}}},"required":["baselines","alerts"]},"CoachBaselineSummary":{"type":"object","properties":{"dimensionType":{"type":"string","enum":["category","merchant"]},"dimensionId":{"type":"string"},"meanRealArs":{"type":"number","nullable":true},"stdRealArs":{"type":"number","nullable":true},"trendSlope":{"type":"number","nullable":true},"sampleSize":{"type":"number","nullable":true},"updatedAt":{"type":"string","nullable":true}},"required":["dimensionType","dimensionId","meanRealArs","stdRealArs","trendSlope","sampleSize","updatedAt"]},"CoachVigilanceAlert":{"type":"object","properties":{"id":{"type":"string"},"alertType":{"type":"string"},"priority":{"type":"number"},"title":{"type":"string"},"message":{"type":"string"},"createdAt":{"type":"string"}},"required":["id","alertType","priority","title","message","createdAt"]},"AiConversation":{"type":"object","properties":{"id":{"type":"string"},"profile_id":{"type":"string"},"family_id":{"type":"string","nullable":true},"title":{"type":"string","nullable":true},"messages":{"type":"array","items":{"nullable":true}},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","profile_id","family_id","title","messages","created_at","updated_at"],"additionalProperties":{"nullable":true}},"ConversationsError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"CreateConversationBody":{"type":"object","properties":{"messages":{"type":"array","items":{"type":"object","additionalProperties":{"nullable":true}}},"title":{"type":"string","nullable":true}}},"UpdateConversationBody":{"type":"object","properties":{"messages":{"type":"array","items":{"type":"object","additionalProperties":{"nullable":true}}},"title":{"type":"string","nullable":true}}},"DashboardBootstrap":{"type":"object","properties":{"profile":{"type":"object","nullable":true,"properties":{"id":{"type":"string"},"family_id":{"type":"string","nullable":true},"full_name":{"type":"string","nullable":true},"avatar_url":{"type":"string","nullable":true},"role":{"type":"string"},"status":{"type":"string","nullable":true},"onboarding_completed_at":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","full_name","avatar_url","role","status","onboarding_completed_at","created_at","updated_at"],"additionalProperties":{"nullable":true}},"accounts":{"type":"array","nullable":true,"items":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"type":{"type":"string"},"account_subtype":{"type":"string","nullable":true},"owner_type":{"type":"string"},"profile_id":{"type":"string","nullable":true},"balance":{"type":"number"},"currency":{"type":"string"},"is_default":{"type":"boolean"},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","name","type","account_subtype","owner_type","profile_id","balance","currency","is_default","created_at","updated_at"],"additionalProperties":{"nullable":true}}},"transactions":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"alerts":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"reminders":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"familyProfiles":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"savings":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"budgets":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"scheduledExpenses":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"scheduledIncomes":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"installments":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"scheduledPayments":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"categoriesExpense":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"categoriesIncome":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}},"required":["profile","accounts","transactions","alerts","reminders","familyProfiles","savings","budgets","scheduledExpenses","scheduledIncomes","installments","scheduledPayments","categoriesExpense","categoriesIncome"]},"DashboardBootstrapError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"TransactionsBootstrap":{"type":"object","properties":{"transactions":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"accounts":{"type":"array","nullable":true,"items":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"type":{"type":"string"},"account_subtype":{"type":"string","nullable":true},"owner_type":{"type":"string"},"profile_id":{"type":"string","nullable":true},"balance":{"type":"number"},"currency":{"type":"string"},"is_default":{"type":"boolean"},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","name","type","account_subtype","owner_type","profile_id","balance","currency","is_default","created_at","updated_at"],"additionalProperties":{"nullable":true}}},"categoriesExpense":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"categoriesIncome":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}},"required":["transactions","accounts","categoriesExpense","categoriesIncome"]},"TransactionsBootstrapError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"AnalysisBootstrap":{"type":"object","properties":{"transactions":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"accounts":{"type":"array","nullable":true,"items":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"type":{"type":"string"},"account_subtype":{"type":"string","nullable":true},"owner_type":{"type":"string"},"profile_id":{"type":"string","nullable":true},"balance":{"type":"number"},"currency":{"type":"string"},"is_default":{"type":"boolean"},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","name","type","account_subtype","owner_type","profile_id","balance","currency","is_default","created_at","updated_at"],"additionalProperties":{"nullable":true}}},"budgets":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"savings":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"recurringPredictions":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}},"required":["transactions","accounts","budgets","savings","recurringPredictions"]},"AnalysisBootstrapError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"PlanningBootstrap":{"type":"object","properties":{"scheduledExpenses":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"scheduledIncomes":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"installments":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"budgets":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"savings":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}},"transactions":{"type":"array","nullable":true,"items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}},"required":["scheduledExpenses","scheduledIncomes","installments","budgets","savings","transactions"]},"PlanningBootstrapError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"Reminder":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","format":"uuid"},"profile_id":{"type":"string","format":"uuid"},"assignee_id":{"type":"string","nullable":true,"format":"uuid"},"due_date":{"type":"string"},"due_time":{"type":"string","nullable":true},"title":{"type":"string"},"notes":{"type":"string","nullable":true},"notify_via_whatsapp":{"type":"boolean"},"completed":{"type":"boolean"},"completed_at":{"type":"string","nullable":true},"related_type":{"type":"string","nullable":true,"enum":["transaction","installment","scheduled_expense",null]},"related_id":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","profile_id","assignee_id","due_date","due_time","title","notes","notify_via_whatsapp","completed","completed_at","related_type","related_id","created_at","updated_at"]},"ReminderCreate":{"type":"object","properties":{"due_date":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"title":{"type":"string","minLength":1},"assignee_id":{"type":"string","nullable":true,"format":"uuid"},"due_time":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true},"notify_via_whatsapp":{"type":"boolean"},"related_type":{"type":"string","nullable":true,"enum":["transaction","installment","scheduled_expense",null]},"related_id":{"type":"string","nullable":true}},"required":["due_date","title"]},"ReminderUpdate":{"type":"object","properties":{"due_date":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"title":{"type":"string","minLength":1},"assignee_id":{"type":"string","nullable":true,"format":"uuid"},"due_time":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true},"notify_via_whatsapp":{"type":"boolean"},"completed":{"type":"boolean"},"completed_at":{"type":"string","nullable":true},"related_type":{"type":"string","nullable":true,"enum":["transaction","installment","scheduled_expense",null]},"related_id":{"type":"string","nullable":true}}},"SendReportOutput":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"emailId":{"type":"string"},"stats":{"type":"object","properties":{"totalTransactions":{"type":"integer"},"totalIncome":{"type":"number"},"totalExpense":{"type":"number"},"balance":{"type":"number"}},"required":["totalTransactions","totalIncome","totalExpense","balance"]}},"required":["success","message"]},"SendReportError":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]},"SendReportInput":{"type":"object","properties":{"email":{"type":"string","format":"email"},"familyId":{"type":"string"},"period":{"type":"object","properties":{"from":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"to":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"}}}},"required":["email","familyId"]},"SavingsGoal":{"type":"object","properties":{"id":{"type":"string"},"family_id":{"type":"string"},"name":{"type":"string"},"target_amount":{"type":"number"},"current_amount":{"type":"number"},"currency":{"type":"string"},"deadline":{"type":"string","nullable":true},"icon":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","name","target_amount","current_amount","currency","deadline","icon","created_at","updated_at"]},"CreateSavingsGoal":{"type":"object","properties":{"name":{"type":"string","minLength":1,"example":"Vacaciones 2027"},"target_amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string","example":"ARS"},"deadline":{"type":"string","nullable":true},"icon":{"type":"string","nullable":true}},"required":["name","target_amount"]},"UpdateSavingsGoal":{"type":"object","properties":{"name":{"type":"string","minLength":1},"target_amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"current_amount":{"type":"number","minimum":0},"deadline":{"type":"string","nullable":true},"icon":{"type":"string","nullable":true}}},"Family":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","name","created_at","updated_at"]},"FamilyUpdate":{"type":"object","properties":{"name":{"type":"string","nullable":true}},"required":["name"]},"ProfileWithFamily":{"allOf":[{"$ref":"#/components/schemas/Profile"},{"type":"object","properties":{"families":{"type":"object","nullable":true,"properties":{"name":{"type":"string","nullable":true}},"required":["name"]}},"required":["families"]}]},"Profile":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","nullable":true,"format":"uuid"},"full_name":{"type":"string","nullable":true},"avatar_url":{"type":"string","nullable":true},"role":{"type":"string"},"status":{"type":"string","nullable":true},"onboarding_completed_at":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","full_name","avatar_url","role","status","onboarding_completed_at","created_at","updated_at"]},"FamilyUserWithAuth":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"full_name":{"type":"string","nullable":true},"avatar_url":{"type":"string","nullable":true},"role":{"type":"string"},"status":{"type":"string","nullable":true},"family_id":{"type":"string","nullable":true,"format":"uuid"},"family_name":{"type":"string","nullable":true},"email":{"type":"string","nullable":true},"phone":{"type":"string","nullable":true},"last_sign_in_at":{"type":"string","nullable":true},"created_at":{"type":"string","nullable":true},"has_mfa":{"type":"boolean"}},"required":["id","full_name","avatar_url","role","status","family_id","family_name","email","phone","last_sign_in_at","created_at","has_mfa"]},"ProfileUpdate":{"type":"object","properties":{"full_name":{"type":"string","nullable":true},"avatar_url":{"type":"string","nullable":true},"status":{"type":"string","nullable":true},"family_id":{"type":"string","nullable":true,"format":"uuid"},"onboarding_completed_at":{"type":"string","nullable":true}}},"FamilyMember":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","format":"uuid"},"profile_id":{"type":"string","nullable":true,"format":"uuid"},"full_name":{"type":"string"},"member_type":{"type":"string"},"is_admin":{"type":"boolean"},"avatar_url":{"type":"string","nullable":true},"birth_date":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","profile_id","full_name","member_type","is_admin","avatar_url","birth_date","created_at","updated_at"]},"FamilyMemberCreate":{"type":"object","properties":{"full_name":{"type":"string","minLength":1},"member_type":{"type":"string","enum":["adult","child","pet"]},"is_admin":{"type":"boolean"},"avatar_url":{"type":"string","nullable":true},"birth_date":{"type":"string","nullable":true}},"required":["full_name","member_type"]},"FamilyMemberUpdate":{"type":"object","properties":{"full_name":{"type":"string","minLength":1},"member_type":{"type":"string","enum":["adult","child","pet"]},"is_admin":{"type":"boolean"},"avatar_url":{"type":"string","nullable":true},"birth_date":{"type":"string","nullable":true}}},"UploadAvatarResponse":{"type":"object","properties":{"key":{"type":"string"},"url":{"type":"string"},"content_type":{"type":"string"},"size_bytes":{"type":"integer"}},"required":["key","url","content_type","size_bytes"]},"MeProfile":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"family_id":{"type":"string","nullable":true,"format":"uuid"},"full_name":{"type":"string","nullable":true},"avatar_url":{"type":"string","nullable":true},"role":{"type":"string"},"status":{"type":"string","nullable":true},"onboarding_completed_at":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","family_id","full_name","avatar_url","role","status","onboarding_completed_at","created_at","updated_at"]},"FinaAlertRow":{"type":"object","properties":{"id":{"type":"string"},"title":{"type":"string"},"message":{"type":"string"},"alert_type":{"type":"string"},"created_at":{"type":"string"},"dismissed":{"type":"boolean"},"action_url":{"type":"string","nullable":true}},"required":["id","title","message","alert_type","created_at","dismissed","action_url"]},"FinaSettings":{"type":"object","nullable":true,"properties":{"budget_alert_threshold":{"type":"number"},"summary_frequency":{"type":"string"},"alert_frequency":{"type":"string"},"notification_channels":{"type":"array","items":{"type":"string"}},"fina_enabled":{"type":"boolean"},"proactive_alerts":{"type":"boolean"}},"required":["budget_alert_threshold","summary_frequency","alert_frequency","notification_channels","fina_enabled","proactive_alerts"]},"FinaSettingsUpsert":{"type":"object","properties":{"budget_alert_threshold":{"type":"integer","minimum":0,"maximum":100},"summary_frequency":{"type":"string"},"alert_frequency":{"type":"string"},"notification_channels":{"type":"array","items":{"type":"string"}},"fina_enabled":{"type":"boolean"},"proactive_alerts":{"type":"boolean"}}},"UserActivityInsert":{"type":"object","properties":{"event_type":{"type":"string","enum":["page_view","session_start"]},"route":{"type":"string","maxLength":512},"user_agent":{"type":"string","nullable":true},"device_summary":{"type":"string","nullable":true}},"required":["event_type","route"]},"UserSessionRow":{"type":"object","properties":{"user_id":{"type":"string"},"full_name":{"type":"string","nullable":true},"email":{"type":"string","nullable":true},"user_agent":{"type":"string","nullable":true},"ip_address":{"type":"string","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["user_id","full_name","email","user_agent","ip_address","created_at","updated_at"]},"RevokeSessionsBody":{"type":"object","properties":{"target_user_id":{"type":"string","format":"uuid"}},"required":["target_user_id"]},"ClientLogInsert":{"type":"object","properties":{"level":{"type":"string","enum":["debug","info","warn","error","critical"]},"category":{"type":"string","enum":["frontend","backend","database","api","auth","integration"]},"source":{"type":"string","maxLength":256},"message":{"type":"string","maxLength":8192},"details":{"nullable":true},"stack_trace":{"type":"string","nullable":true,"maxLength":16384},"session_id":{"type":"string","nullable":true,"maxLength":128},"environment":{"type":"string","nullable":true,"maxLength":64}},"required":["level","category","source","message"]},"WhatsAppSessionRow":{"type":"object","properties":{"id":{"type":"string"},"phone_number":{"type":"string"},"contact_name":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"profile_full_name":{"type":"string","nullable":true},"last_interaction":{"type":"string"},"active":{"type":"boolean"}},"required":["id","phone_number","contact_name","profile_id","profile_full_name","last_interaction","active"]},"WhatsAppMessageRow":{"type":"object","properties":{"id":{"type":"string"},"direction":{"type":"string","enum":["inbound","outbound"]},"body":{"type":"string","nullable":true},"created_at":{"type":"string"},"profile_id":{"type":"string","nullable":true},"profile_full_name":{"type":"string","nullable":true}},"required":["id","direction","body","created_at","profile_id","profile_full_name"]},"WhatsAppConversationGroup":{"type":"object","properties":{"profileId":{"type":"string"},"profileName":{"type":"string"},"profileAvatarUrl":{"type":"string","nullable":true},"phoneNumber":{"type":"string"},"lastMessage":{"type":"string"},"lastMessageAt":{"type":"string"},"messageCount":{"type":"number"},"active":{"type":"boolean"}},"required":["profileId","profileName","profileAvatarUrl","phoneNumber","lastMessage","lastMessageAt","messageCount","active"]},"WhatsAppThreadMessage":{"type":"object","properties":{"id":{"type":"string"},"direction":{"type":"string","enum":["inbound","outbound"]},"body":{"type":"string"},"created_at":{"type":"string"},"attachments":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppThreadAttachment"}}},"required":["id","direction","body","created_at","attachments"]},"WhatsAppThreadAttachment":{"type":"object","properties":{"url":{"type":"string"},"content_type":{"type":"string"},"caption":{"type":"string","nullable":true}},"required":["url","content_type","caption"]},"WhatsAppLastActivity":{"type":"object","properties":{"lastMessageAt":{"type":"string","nullable":true},"totalMessages":{"type":"number"},"lastDirection":{"type":"string","nullable":true,"enum":["inbound","outbound",null]}},"required":["lastMessageAt","totalMessages","lastDirection"]},"PushSubscribeRequest":{"type":"object","properties":{"endpoint":{"type":"string","format":"uri"},"keys":{"type":"object","properties":{"p256dh":{"type":"string","minLength":1},"auth":{"type":"string","minLength":1}},"required":["p256dh","auth"]}},"required":["endpoint","keys"]},"PushUnsubscribeRequest":{"type":"object","properties":{"endpoint":{"type":"string","format":"uri"}},"required":["endpoint"]}},"parameters":{}},"paths":{"/api/health":{"get":{"tags":["Health"],"summary":"Liveness + optional probe","description":"Sin `?probe=1` devuelve `{ ok, timestamp }` (liveness barato, público). Con `?probe=1` ejecuta checks contra D1, OpenAI, KV y Vectorize (rate-limit 10/h por IP). `?model=` es herramienta de ops y requiere `X-Cron-Secret`.","security":[],"parameters":[{"schema":{"type":"string","enum":["1"],"description":"Setear `1` para correr el full probe."},"required":false,"description":"Setear `1` para correr el full probe.","name":"probe","in":"query"},{"schema":{"type":"string","description":"Probe puntual de un modelo del gateway (ej. `openai/gpt-5.4`). Devuelve si responde + latencia. Herramienta de ops — requiere header `X-Cron-Secret`."},"required":false,"description":"Probe puntual de un modelo del gateway (ej. `openai/gpt-5.4`). Devuelve si responde + latencia. Herramienta de ops — requiere header `X-Cron-Secret`.","name":"model","in":"query"}],"responses":{"200":{"description":"Health snapshot.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"}}}},"401":{"description":"Falta o no coincide `X-Cron-Secret` (solo para `?model=`).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"429":{"description":"Rate limit del probe excedido (`?probe=1`, 10/h por IP).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"resetAt":{"type":"number"}},"required":["error"]}}}}}}},"/api/auth/signout":{"post":{"tags":["auth"],"summary":"Cierra sesión server-side","description":"Borra las 4 cookies firmadas (fina_ctx, fina_device, sb-access-token, fina_last_family) y revoca el row en user_devices del device actual (best effort). No requiere Bearer auth — la sola presencia de la cookie firmada permite identificar el device a revocar. Si no hay cookie válida, solo borra cookies sin tocar DB. Rate-limit 30/h por IP para evitar abuso.","security":[],"responses":{"200":{"description":"Sesión cerrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignoutResponse"}}}}}}},"/api/agent":{"post":{"tags":["Agent"],"summary":"Chat with Fina (JSON or SSE)","description":"Default response is JSON `AgentOutput`. With `stream: true` the response is `text/event-stream`; the JSON schema below describes the final aggregated shape — partial chunks share the same fields.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentRequest"}}}},"responses":{"200":{"description":"Final `AgentOutput` (or SSE stream when `stream: true`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentOutput"}},"text/event-stream":{"schema":{"type":"string","description":"SSE frames. Each frame is a JSON-encoded partial AgentOutput; the last frame carries the full final shape."}}}},"401":{"description":"Missing or invalid Bearer token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded (500 req/h per profile).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/whatsapp-webhook":{"get":{"tags":["WhatsApp"],"summary":"Meta webhook verification handshake","description":"Public endpoint Meta hits when configuring the webhook. Returns the `hub.challenge` echo when the verify token matches `WHATSAPP_VERIFY_TOKEN`.","security":[],"parameters":[{"schema":{"type":"string"},"required":false,"name":"hub.mode","in":"query"},{"schema":{"type":"string"},"required":false,"name":"hub.verify_token","in":"query"},{"schema":{"type":"string"},"required":false,"name":"hub.challenge","in":"query"}],"responses":{"200":{"description":"Echo of `hub.challenge` (text).","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"Verify token mismatch.","content":{"text/plain":{"schema":{"type":"string"}}}}}},"post":{"tags":["WhatsApp"],"summary":"Inbound WhatsApp message webhook","description":"Meta posts inbound messages here. Body is HMAC-verified against `META_APP_SECRET` (when configured). Always returns 200 to avoid Meta retry storms; invalid-signature payloads are dropped silently. Forwards each message to the `WHATSAPP_QUEUE` Queue (Paid plan) or processes inline (Free plan).","security":[{"metaWebhookHmac":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"object":{"type":"string"},"entry":{"type":"array","items":{"nullable":true}}},"additionalProperties":{"nullable":true}}}}},"responses":{"200":{"description":"Acknowledged (always 200, even on invalid signature).","content":{"text/plain":{"schema":{"type":"string","enum":["ok"]}}}}}}},"/api/webhooks/mp-inbox":{"post":{"tags":["Webhooks"],"summary":"Inbound Mercado Pago (Resend email.received)","description":"Recibe los emails de Mercado Pago reenviados desde Gmail vía Resend inbound. Firma Svix obligatoria (`RESEND_MP_WEBHOOK_SECRET`). Parsea monto/comercio/n° de operación y registra la transacción con dedup por operación.","security":[{"svixSignature":[]}],"responses":{"200":{"description":"Evento procesado (o ignorado con motivo).","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"},"status":{"type":"string"}},"required":["ok"]}}}},"401":{"description":"Firma Svix inválida.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"503":{"description":"Webhook sin configurar (falta RESEND_MP_WEBHOOK_SECRET).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/webhooks/mp-inbox/admin/setup":{"post":{"tags":["Webhooks"],"summary":"Crea el webhook email.received en Resend (ops)","description":"Usa el RESEND_API_KEY del Worker para crear el webhook de Resend apuntando a este endpoint y devuelve el signing secret (guardarlo con `wrangler secret put RESEND_MP_WEBHOOK_SECRET`). Gate: header `X-Ops-Token` = MP_OPS_TOKEN.","security":[{"opsToken":[]}],"responses":{"200":{"description":"Webhook creado (o listado si ya existía).","content":{"application/json":{"schema":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}}},"401":{"description":"Token de ops inválido.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/webhooks/mp-inbox/admin/recent":{"get":{"tags":["Webhooks"],"summary":"Últimos emails recibidos en la bandeja MP (ops)","description":"Lista los últimos emails archivados (estado, parseo, errores). Sirve para leer el código de confirmación del auto-forward de Gmail y auditar el pipeline. Gate: header `X-Ops-Token`.","security":[{"opsToken":[]}],"responses":{"200":{"description":"Últimos 25 emails.","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}}}},"401":{"description":"Token de ops inválido.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/agent-config":{"get":{"tags":["Agent Config"],"summary":"Read Fina settings for current profile","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Effective settings (DB values with env defaults applied).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentSettings"}}}},"401":{"description":"Missing or invalid Bearer token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"patch":{"tags":["Agent Config"],"summary":"Upsert Fina settings for current profile","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentSettingsPatch"}}}},"responses":{"200":{"description":"Settings written.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}},"required":["ok"]}}}},"400":{"description":"Invalid model or payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid Bearer token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Database write failure.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/calendar/events":{"get":{"tags":["Calendar"],"summary":"List Google Calendar events (pending integration)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Stub response. Real integration tracked in PWR §Calendar.","content":{"application/json":{"schema":{"type":"object","properties":{"events":{"type":"array","items":{"nullable":true}},"created":{"type":"boolean"},"note":{"type":"string"}},"required":["note"]}}}}}},"post":{"tags":["Calendar"],"summary":"Create a Calendar event (pending integration)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}}},"responses":{"501":{"description":"Not implemented yet.","content":{"application/json":{"schema":{"type":"object","properties":{"events":{"type":"array","items":{"nullable":true}},"created":{"type":"boolean"},"note":{"type":"string"}},"required":["note"]}}}}}}},"/api/send-push":{"post":{"tags":["Push"],"summary":"Enviar una notificación Web Push (cron-only)","description":"Autorizado vía header compartido `X-Cron-Secret`. Encripta (aes128gcm) + firma VAPID (ES256) sobre WebCrypto del runtime — sin dependencia npm. Hace fan-out a todas las suscripciones del perfil y poda endpoints muertos (404/410). Si VAPID no está configurado en este entorno, responde `ok:true` + `skipped`.","security":[{"cronSecret":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PushRequest"}}}},"responses":{"200":{"description":"Resultado del fan-out (puede ser sent=0 si no hay suscripciones).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PushResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/ocr/receipt":{"post":{"tags":["OCR"],"summary":"Extract structured fields from a receipt image","description":"Vision-based extraction (gpt-5-mini con reasoning). Result cached in KV by `sha256` 24h + AI Gateway cache; subsequent calls with same hash hit cache.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReceiptOcrRequest"}}}},"responses":{"200":{"description":"Extracted fields. `cached: true` when served from KV.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReceiptOcrResult"}}}},"400":{"description":"Missing or invalid image.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid Bearer token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/ocr/statement":{"post":{"tags":["OCR"],"summary":"Parse a bank statement PDF (pending implementation)","description":"Stub. The actual PDF parser lives in `tools/bulk-import.ts` (uses `unpdf` for CF compatibility); this HTTP entry will wrap it later.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"pdfBase64":{"type":"string"}},"required":["pdfBase64"]}}}},"responses":{"501":{"description":"Not implemented yet.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[false]},"note":{"type":"string"}},"required":["ok","note"]}}}}}}},"/api/places/autocomplete":{"post":{"tags":["Places"],"summary":"Google Places autocomplete (server-side proxy)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"input":{"type":"string","example":"Cafe Martinez"},"regionCodes":{"type":"array","items":{"type":"string"},"example":["ar"]}},"required":["input"]}}}},"responses":{"200":{"description":"Place suggestions. Vacío si no hay key o input vacío.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlacesAutocompleteResponse"}}}},"429":{"description":"Rate limit excedido.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"resetAt":{"type":"number"}},"required":["error"]}}}}}}},"/api/places/details":{"post":{"tags":["Places"],"summary":"Google Places details by placeId (server-side proxy)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"placeId":{"type":"string","example":"places/ChIJ..."}},"required":["placeId"]}}}},"responses":{"200":{"description":"Place details, o `details:null` si no resolvió.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlacesDetailsResponse"}}}},"429":{"description":"Rate limit excedido.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"resetAt":{"type":"number"}},"required":["error"]}}}}}},"get":{"tags":["Places"],"summary":"Google Places details by placeId (query variant)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","example":"places/ChIJ..."},"required":true,"name":"placeId","in":"query"}],"responses":{"200":{"description":"Place details, o `details:null` si no resolvió.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlacesDetailsResponse"}}}},"429":{"description":"Rate limit excedido.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"resetAt":{"type":"number"}},"required":["error"]}}}}}}},"/api/places/nearby":{"post":{"tags":["Places"],"summary":"Suggest place name from coords (server-side proxy)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"latitude":{"type":"number","example":-34.6},"longitude":{"type":"number","example":-58.4},"radiusMeters":{"type":"number","example":100}},"required":["latitude","longitude"]}}}},"responses":{"200":{"description":"Closest place name, o `placeName:null` si no resolvió.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlacesNearbyResponse"}}}},"429":{"description":"Rate limit excedido.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"resetAt":{"type":"number"}},"required":["error"]}}}}}}},"/api/devices":{"get":{"tags":["Devices"],"summary":"List trusted devices","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Devices ordered by `last_seen` desc.","content":{"application/json":{"schema":{"type":"object","properties":{"devices":{"type":"array","items":{"$ref":"#/components/schemas/Device"}}},"required":["devices"]}}}},"500":{"description":"DB error.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"}},"required":["error","message"]}}}}}}},"/api/devices/{id}":{"patch":{"tags":["Devices"],"summary":"Rename a device","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"label":{"type":"string","minLength":1,"maxLength":80}},"required":["label"]}}}},"responses":{"200":{"description":"Renamed.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}},"required":["ok"]}}}},"404":{"description":"Not found.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"}},"required":["error","message"]}}}}}},"delete":{"tags":["Devices"],"summary":"Revoke a device","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Revoked.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}},"required":["ok"]}}}},"404":{"description":"Not found.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"}},"required":["error","message"]}}}}}}},"/api/brands":{"get":{"tags":["Brands"],"summary":"List all known brands (registry)","security":[],"responses":{"200":{"description":"Brands ordered by canonical_name","content":{"application/json":{"schema":{"type":"object","properties":{"brands":{"type":"array","items":{"$ref":"#/components/schemas/Brand"}}},"required":["brands"]}}}}}}},"/api/weather":{"get":{"tags":["Weather"],"summary":"Current weather (cached 30 min via KV)","security":[],"parameters":[{"schema":{"type":"string","example":"Buenos Aires"},"required":false,"name":"city","in":"query"},{"schema":{"type":"number","nullable":true},"required":false,"name":"lat","in":"query"},{"schema":{"type":"number","nullable":true},"required":false,"name":"lon","in":"query"}],"responses":{"200":{"description":"Current weather. `cached: true` cuando vino del KV.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WeatherData"}}}},"429":{"description":"Rate limit excedido (30/h por IP).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"resetAt":{"type":"number"}},"required":["error"]}}}},"500":{"description":"Tomorrow.io error or config missing","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/admin/ai-usage":{"get":{"tags":["Admin"],"summary":"AI usage rollup for the admin dashboard","description":"Aggregates `ai_usage_logs` for the caller’s family. Range defaults to current UTC month. Granularity chooses the time-series bucket size. Includes monthly projection (linear and MA7) plus the configured budget for delta computation.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"date-time","example":"2026-05-01T00:00:00Z"},"required":false,"name":"from","in":"query"},{"schema":{"type":"string","format":"date-time","example":"2026-05-31T23:59:59Z"},"required":false,"name":"to","in":"query"},{"schema":{"type":"string","enum":["hour","day"],"default":"day"},"required":false,"name":"granularity","in":"query"}],"responses":{"200":{"description":"Aggregated usage.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AiUsageAggregate"}}}},"401":{"description":"Missing or invalid Bearer token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Caller is not an admin of the family.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/admin/ai-provider-info":{"get":{"tags":["Admin"],"summary":"AI provider runtime info (provider, default model, key fingerprint)","description":"Returns the configured AI provider, default model, whether traffic is routed via Cloudflare AI Gateway, and a redacted fingerprint of the API key (first 7 + last 4 chars) so admins can verify which key is active without exposing the full secret.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Provider info.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AiProviderInfo"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/admin/ai-budget":{"get":{"tags":["Admin"],"summary":"Get the AI budget config for the family","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Config row, or `null` when not yet configured.","content":{"application/json":{"schema":{"type":"object","properties":{"config":{"$ref":"#/components/schemas/AiBudgetConfig"}},"required":["config"]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"put":{"tags":["Admin"],"summary":"Upsert the AI budget config for the family","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AiBudgetUpdate"}}}},"responses":{"200":{"description":"Saved config.","content":{"application/json":{"schema":{"type":"object","properties":{"config":{"$ref":"#/components/schemas/AiBudgetConfig"}},"required":["config"]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB upsert failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/admin/queue/dlq":{"get":{"tags":["admin"],"summary":"Lista mensajes en el archivo DLQ de WhatsApp","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":500,"default":100},"required":false,"name":"limit","in":"query"},{"schema":{"type":"boolean","nullable":true,"default":false},"required":false,"name":"include_replayed","in":"query"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DlqListResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/admin/queue/dlq/replay":{"post":{"tags":["admin"],"summary":"Re-enqueua una fila del archivo DLQ a whatsapp-messages","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","format":"uuid"}},"required":["id"]}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DlqReplayResponse"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"Already replayed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Queue unavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/admin/learning/rebuild":{"post":{"tags":["Admin"],"summary":"Rebuild learning patterns (merchant, temporal, recurring)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":false,"name":"family_id","in":"query"}],"responses":{"200":{"description":"Rebuild complete","content":{"application/json":{"schema":{"type":"object","properties":{"results":{"type":"array","items":{"$ref":"#/components/schemas/LearningRebuildResult"}},"duration_ms":{"type":"integer"}},"required":["results","duration_ms"]}}}},"403":{"description":"family_id del query no coincide con la familia del admin.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LearningError"}}}},"500":{"description":"Rebuild failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LearningError"}}}}}}},"/api/admin/learning/audit-history":{"post":{"tags":["Admin"],"summary":"Audit historical transactions to enrich learning","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":true,"name":"from","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"family_id","in":"query"}],"responses":{"200":{"description":"Audit complete (SQL-level only, no LLM call yet)","content":{"application/json":{"schema":{"type":"object","properties":{"from":{"type":"string"},"families_audited":{"type":"integer"},"patterns_after":{"type":"integer"},"duration_ms":{"type":"integer"}},"required":["from","families_audited","patterns_after","duration_ms"]}}}},"403":{"description":"family_id del query no coincide con la familia del admin.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LearningError"}}}},"500":{"description":"Audit failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LearningError"}}}}}}},"/api/admin/vectorize/backfill-v2":{"post":{"tags":["Admin"],"summary":"Backfill memorias del Vectorize v1 (1536d) al v2 (bge-m3 1024d)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"family_id","in":"query"}],"responses":{"200":{"description":"Backfill complete","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VectorizeBackfillResult"}}}},"500":{"description":"Backfill failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VectorizeAdminError"}}}}}}},"/api/admin/stats/v2":{"get":{"tags":["Admin"],"summary":"Stats v2 — consolida D1 + Workers AI + Gateway + bindings","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"AdminStatsV2 payload","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminStatsV2"}}}}}}},"/api/admin/fina-sprint":{"get":{"tags":["Admin"],"summary":"Métricas consolidadas del sprint Fina v2.2","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Snapshot de todos los features v2.2 + extras","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FinaSprintMetrics"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/admin/cron/run":{"post":{"tags":["Admin"],"summary":"Trigger manual de cron proactivo","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","enum":["proactive_analysis","reminders","proactive_summary","deep_vigilance"],"example":"proactive_analysis"},"required":true,"name":"name","in":"query"}],"responses":{"200":{"description":"Cron ejecutado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"},"name":{"type":"string"},"duration_ms":{"type":"integer"}},"required":["ok","name","duration_ms"]}}}},"500":{"description":"Cron failed","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/whatsapp-templates/status":{"get":{"tags":["Admin"],"summary":"Descubre el WABA ID + scopes y lista los templates de WhatsApp","security":[{"cronSecret":[]}],"responses":{"200":{"description":"Estado de templates + discovery.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WhatsAppTemplatesStatus"}}}},"400":{"description":"Error de discovery.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WhatsAppTemplatesError"}}}}}}},"/api/whatsapp-templates/sync":{"post":{"tags":["Admin"],"summary":"Crea los templates de WhatsApp que falten (los manda a revisión de Meta)","security":[{"cronSecret":[]}],"responses":{"200":{"description":"Resultado por template.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WhatsAppTemplatesSyncResponse"}}}},"400":{"description":"Error de discovery.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WhatsAppTemplatesError"}}}}}}},"/api/admin/integrations/test":{"get":{"tags":["Admin"],"summary":"Probe an integration and report its honest status","description":"Pinguea la integración indicada por `id` desde el Worker (la API key nunca toca el cliente). Devuelve `not_implemented` cuando no hay probe real para ese `id`.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","minLength":1,"example":"tomorrow"},"required":true,"name":"id","in":"query"}],"responses":{"200":{"description":"Resultado del probe.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/IntegrationProbeResult"}}}},"400":{"description":"Falta `id`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/IntegrationError"}}}}}}},"/api/admin/github/sync":{"post":{"tags":["Admin"],"summary":"Sync recent GitHub commits into the audit trail","description":"Fetches recent commits from the GitHub API and upserts them into `github_commits` (dedupe por `sha`). Requiere `GITHUB_TOKEN` seteado como secret del Worker.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GitHubSyncRequest"}}}},"responses":{"200":{"description":"Sync OK — cuántos commits se trajeron e insertaron.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GitHubSyncResult"}}}},"400":{"description":"owner/repo faltantes y sin defaults.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GitHubError"}}}},"502":{"description":"GitHub API devolvió un error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GitHubError"}}}},"503":{"description":"GITHUB_TOKEN no configurado.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GitHubError"}}}}}}},"/api/receipts/{key}":{"get":{"tags":["Receipts"],"summary":"Servir un receipt desde R2","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","example":"receipts%2Ffamily-uuid%2F1234567890-photo.jpg"},"required":true,"name":"key","in":"path"}],"responses":{"200":{"description":"Bytes del archivo","content":{"application/octet-stream":{"schema":{"type":"string"}}}},"403":{"description":"Caller no tiene acceso a este receipt","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Receipt no existe","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/avatars/{key}":{"get":{"tags":["Avatars"],"summary":"Servir un avatar desde R2 (público)","security":[],"parameters":[{"schema":{"type":"string","example":"avatars%2Ffamily-uuid%2Fprofile-uuid_1700000000.jpg"},"required":true,"name":"key","in":"path"}],"responses":{"200":{"description":"Bytes de la imagen","content":{"application/octet-stream":{"schema":{"type":"string"}}}},"403":{"description":"Key fuera del namespace avatars/","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Avatar no existe","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/favicon":{"get":{"tags":["Misc"],"summary":"Favicon de comercio (proxy same-origin, siempre 200)","security":[],"parameters":[{"schema":{"type":"string","minLength":1,"maxLength":255,"example":"mercadolibre.com.ar"},"required":true,"name":"domain","in":"query"}],"responses":{"200":{"description":"Imagen del favicon (real o placeholder SVG).","content":{"image/svg+xml":{"schema":{"type":"string"}}}}}}},"/api/admin/reports/monthly/render":{"post":{"tags":["Reports"],"summary":"Admin: render monthly PDF report and persist to R2","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminRenderMonthlyInput"}}}},"responses":{"200":{"description":"PDF rendered and persisted.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminRenderMonthlyOutput"}}}},"400":{"description":"Bad input.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"403":{"description":"family_id del body no coincide con la familia del admin.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"Render or upload error.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"}},"required":["error","message"]}}}}}}},"/api/reports/render/{familyId}/{yearMonth}":{"get":{"tags":["Reports"],"summary":"Internal: server-rendered HTML for Browser Run","description":"Not user-facing. Browser Run fetches this URL with an HMAC `secret` query param to render the report HTML, then captures it as PDF. Returns 404 to anyone without a valid secret so the route is invisible to scanners.","security":[{"reportToken":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"familyId","in":"path"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}$","example":"2026-04"},"required":true,"name":"yearMonth","in":"path"},{"schema":{"type":"string"},"required":true,"name":"secret","in":"query"}],"responses":{"200":{"description":"Report HTML.","content":{"text/html":{"schema":{"type":"string"}}}},"404":{"description":"Invalid or expired secret."}}}},"/api/reports/monthly/{token}":{"get":{"tags":["Reports"],"summary":"Public: download monthly PDF via signed token","description":"No Bearer required — the HMAC token in the path encodes (family_id, year_month, exp). 404 on invalid/expired token.","security":[{"reportToken":[]}],"parameters":[{"schema":{"type":"string"},"required":true,"name":"token","in":"path"}],"responses":{"200":{"description":"PDF binary.","content":{"application/pdf":{"schema":{"type":"string"}}}},"404":{"description":"Token invalid or PDF missing."}}}},"/api/me/ai-usage":{"get":{"tags":["Me"],"summary":"Caller’s own AI usage rollup","description":"Same shape as the admin endpoint but filtered to the caller’s `profile_id` and trimmed (no top-requests, no per-profile breakdown — there is only one). Useful for a per-user settings panel.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"date-time"},"required":false,"name":"from","in":"query"},{"schema":{"type":"string","format":"date-time"},"required":false,"name":"to","in":"query"},{"schema":{"type":"string","enum":["hour","day"],"default":"day"},"required":false,"name":"granularity","in":"query"}],"responses":{"200":{"description":"Aggregated usage for the caller.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MeAiUsageAggregate"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/uploads/receipt":{"post":{"tags":["Me"],"summary":"Subir un comprobante a R2 (sin tx asociada todavía)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Comprobante subido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadReceiptResponse"}}}},"400":{"description":"Caller sin family_id, multipart inválido o MIME rechazado","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"413":{"description":"Archivo excede el cap de 10 MB","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"R2 error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/deductibles":{"get":{"tags":["Me"],"summary":"Export gastos deducibles para AFIP/contador","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","example":"2026-01-01"},"required":true,"name":"from","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","example":"2026-12-31"},"required":true,"name":"to","in":"query"},{"schema":{"type":"string","enum":["csv","json"],"default":"json"},"required":false,"name":"format","in":"query"}],"responses":{"200":{"description":"Listado de deducibles en el rango","content":{"application/json":{"schema":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"count":{"type":"integer"},"total_ars":{"type":"number"},"total_usd":{"type":"number"},"rows":{"type":"array","items":{"$ref":"#/components/schemas/DeductibleRow"}}},"required":["from","to","count","total_ars","total_usd","rows"]}},"text/csv":{"schema":{"type":"string"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/export/transactions.csv":{"get":{"tags":["Me"],"summary":"Exportar transacciones de la familia a CSV (server-side)","description":"Genera un CSV bien escapado (RFC 4180 + BOM UTF-8 para Excel) con las transacciones de la familia del caller. Scoping `family_id` + soft-delete. Filtros: rango de fechas, tipo, categoría, miembro (spender). Rate-limit 60/h.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"from","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"to","in":"query"},{"schema":{"type":"string","enum":["income","expense"]},"required":false,"name":"type","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"category_id","in":"query"},{"schema":{"type":"string","format":"uuid","description":"profile_id del miembro de la familia para filtrar (spender)."},"required":false,"description":"profile_id del miembro de la familia para filtrar (spender).","name":"member","in":"query"}],"responses":{"200":{"description":"CSV adjunto (text/csv).","content":{"text/csv":{"schema":{"type":"string"}}}},"400":{"description":"Caller sin family_id.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/export/monthly.pdf":{"get":{"tags":["Me"],"summary":"Exportar resumen mensual de la familia a PDF (Browser Run)","description":"Renderiza el resumen mensual de la familia del caller como PDF reusando el endpoint interno de `routes/reports.ts` vía Browser Run. El `family_id` sale del auth, no del query. Rate-limit 60/h (cuenta contra el cap de Browser Run).","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}$","example":"2026-05"},"required":true,"name":"year_month","in":"query"}],"responses":{"200":{"description":"PDF adjunto (application/pdf).","content":{"application/pdf":{"schema":{"type":"string"}}}},"400":{"description":"Caller sin family_id o config faltante.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"Error de render.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"}},"required":["error","message"]}}}}}}},"/api/me/transactions/{id}/audit":{"get":{"tags":["Me"],"summary":"Audit log de una transacción","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Listado de cambios ordenado DESC por fecha","content":{"application/json":{"schema":{"type":"object","properties":{"transaction_id":{"type":"string","format":"uuid"},"count":{"type":"integer"},"entries":{"type":"array","items":{"$ref":"#/components/schemas/TransactionAuditRow"}}},"required":["transaction_id","count","entries"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/transactions/{id}/attachments":{"get":{"tags":["Me"],"summary":"Listar adjuntos (1:N) de una transacción","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Listado de adjuntos ordenado ASC por created_at","content":{"application/json":{"schema":{"type":"object","properties":{"transaction_id":{"type":"string","format":"uuid"},"count":{"type":"integer"},"attachments":{"type":"array","items":{"$ref":"#/components/schemas/TransactionAttachmentRow"}}},"required":["transaction_id","count","attachments"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Transacción no encontrada o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Subir adjuntos a una transacción existente","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Adjuntos subidos correctamente","content":{"application/json":{"schema":{"type":"object","properties":{"count":{"type":"integer"},"attachments":{"type":"array","items":{"$ref":"#/components/schemas/TransactionAttachmentRow"}}},"required":["count","attachments"]}}}},"400":{"description":"Caller sin family_id, multipart inválido o tipo MIME rechazado","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Transacción no encontrada o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"413":{"description":"Algún archivo excede el cap de 10 MB","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"R2 / DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/transactions":{"get":{"tags":["Me"],"summary":"Listar transacciones de la familia (paginado)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":500,"default":200},"required":false,"name":"limit","in":"query"},{"schema":{"type":"integer","nullable":true,"minimum":0,"default":0},"required":false,"name":"offset","in":"query"},{"schema":{"type":"string","enum":["income","expense"]},"required":false,"name":"type","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"from","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"to","in":"query"},{"schema":{"type":"string","maxLength":200},"required":false,"name":"search","in":"query"}],"responses":{"200":{"description":"Listado ordenado por date DESC, created_at DESC","content":{"application/json":{"schema":{"type":"object","properties":{"count":{"type":"integer"},"total":{"type":"integer"},"transactions":{"type":"array","items":{"$ref":"#/components/schemas/Transaction"}}},"required":["count","total","transactions"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}},"post":{"tags":["Me"],"summary":"Crear una transacción","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateTransactionBody"}}}},"responses":{"200":{"description":"Transacción creada (con joins embebidos)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Transaction"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}}},"/api/me/transactions/counts-by-profile":{"get":{"tags":["Me"],"summary":"Conteo de transacciones reales por miembro (excluye transfers)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Record<profileId, count>","content":{"application/json":{"schema":{"type":"object","additionalProperties":{"type":"integer"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}}},"/api/me/transactions/{id}":{"get":{"tags":["Me"],"summary":"Obtener una transacción por id","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Transacción encontrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Transaction"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"404":{"description":"No encontrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}},"patch":{"tags":["Me"],"summary":"Actualizar una transacción","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateTransactionBody"}}}},"responses":{"200":{"description":"Transacción actualizada (con joins embebidos)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Transaction"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"404":{"description":"No encontrada o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}},"delete":{"tags":["Me"],"summary":"Soft-delete de una transacción (deleted_at)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Eliminada (soft)","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"},"id":{"type":"string"}},"required":["ok","id"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"404":{"description":"No encontrada o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}}},"/api/me/transactions/{id}/items":{"get":{"tags":["Me"],"summary":"Listar items (desglose) de una transacción","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Items ordenados ASC por created_at","content":{"application/json":{"schema":{"type":"object","properties":{"transaction_id":{"type":"string"},"count":{"type":"integer"},"items":{"type":"array","items":{"$ref":"#/components/schemas/TransactionItem"}}},"required":["transaction_id","count","items"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"404":{"description":"Transacción no encontrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}},"post":{"tags":["Me"],"summary":"Agregar un item al desglose de una transacción","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateTransactionItemBody"}}}},"responses":{"200":{"description":"Item creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionItem"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"404":{"description":"Transacción no encontrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}}},"/api/me/transactions/{id}/items/{itemId}":{"delete":{"tags":["Me"],"summary":"Borrar un item del desglose de una transacción","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"},{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"itemId","in":"path"}],"responses":{"200":{"description":"Item borrado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"},"id":{"type":"string"}},"required":["ok","id"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"404":{"description":"Item o transacción no encontrados","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsError"}}}}}}},"/api/me/analytics":{"get":{"tags":["Me"],"summary":"Agregados de transacciones por período (server-side, en pesos)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","enum":["last_7_days","last_15_days","this_month","last_3_months","last_6_months","this_year","custom"]},"required":true,"name":"period","in":"query"},{"schema":{"type":"string"},"required":false,"name":"start","in":"query"},{"schema":{"type":"string"},"required":false,"name":"end","in":"query"},{"schema":{"type":"string"},"required":false,"name":"profile_id","in":"query"}],"responses":{"200":{"description":"Totales, desgloses por categoría/miembro, serie temporal, top movimientos y no-convertidas. Montos en PESOS.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MeAnalytics"}}}},"400":{"description":"Caller sin family_id, rango custom inválido o profile ajeno","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalyticsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalyticsError"}}}}}}},"/api/me/transfers":{"post":{"tags":["Me"],"summary":"Transferencia interna atómica entre cuentas de la familia","description":"Crea las DOS patas (expense en origen, income en destino) en una sola transacción D1: o quedan ambas o ninguna.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateTransferBody"}}}},"responses":{"201":{"description":"Transferencia creada (ambas patas)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateTransferResponse"}}}},"400":{"description":"Body inválido, cuentas inválidas o falta cotización","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransfersError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransfersError"}}}}}}},"/api/me/accounts":{"get":{"tags":["Me"],"summary":"Listar cuentas de la familia","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Cuentas de la familia ordenadas por nombre","content":{"application/json":{"schema":{"type":"object","properties":{"count":{"type":"integer"},"accounts":{"type":"array","items":{"$ref":"#/components/schemas/Account"}}},"required":["count","accounts"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear cuenta","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AccountInsert"}}}},"responses":{"200":{"description":"Cuenta creada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Account"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/accounts/{id}":{"patch":{"tags":["Me"],"summary":"Actualizar cuenta","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AccountUpdate"}}}},"responses":{"200":{"description":"Cuenta actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Account"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Cuenta no encontrada o de otra familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"409":{"description":"No se puede cambiar moneda/owner: la cuenta tiene transacciones","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Borrar cuenta","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Cuenta borrada","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Cuenta no encontrada o de otra familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"409":{"description":"La cuenta tiene transacciones y no se puede borrar","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/accounts/{id}/default":{"post":{"tags":["Me"],"summary":"Marcar/desmarcar cuenta default para (profile_id, currency)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AccountSetDefault"}}}},"responses":{"200":{"description":"Default actualizado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Cuenta no encontrada / no matchea (profile_id, currency)","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/budgets":{"get":{"tags":["Me"],"summary":"Listar presupuestos de la familia (con categoría)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$","example":"2026-06"},"required":false,"name":"month","in":"query"}],"responses":{"200":{"description":"Listado de presupuestos ordenado DESC por month","content":{"application/json":{"schema":{"type":"object","properties":{"budgets":{"type":"array","items":{"$ref":"#/components/schemas/BudgetRow"}}},"required":["budgets"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"post":{"tags":["Me"],"summary":"Crear presupuesto","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"category_id":{"type":"string","format":"uuid"},"month":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$"},"amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string"},"goal_description":{"type":"string","nullable":true}},"required":["category_id","month","amount"]}}}},"responses":{"200":{"description":"Presupuesto creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Budget"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"Ya existe un presupuesto para esa categoría y mes","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/budgets/{id}":{"patch":{"tags":["Me"],"summary":"Editar presupuesto","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"category_id":{"type":"string","format":"uuid"},"month":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$"},"amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string"},"goal_description":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Presupuesto actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Budget"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No encontrado o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"delete":{"tags":["Me"],"summary":"Borrar presupuesto","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Presupuesto borrado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No encontrado o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/budgets/status":{"get":{"tags":["Me"],"summary":"Estado de presupuestos (view budget_status, solo lectura)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$","example":"2026-06"},"required":false,"name":"month","in":"query"}],"responses":{"200":{"description":"Filas de budget_status para la familia","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"array","items":{"$ref":"#/components/schemas/BudgetStatusRow"}}},"required":["status"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/categories":{"get":{"tags":["Me"],"summary":"Categorías globales + custom de la familia","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","enum":["income","expense"],"example":"expense","description":"Filtra por tipo de categoría"},"required":false,"description":"Filtra por tipo de categoría","name":"type","in":"query"}],"responses":{"200":{"description":"Listado de categorías (custom-first)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Category"}}}}},"401":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear categoría o subcategoría de la familia","security":[{"bearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateCategoryBody"}}}},"responses":{"200":{"description":"Creada (o reactivada/existente — ver `note`).","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"note":{"type":"string"}},"required":["id"]}}}},"400":{"description":"Parent inválido o payload malformado.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"401":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/categories/{id}":{"patch":{"tags":["Me"],"summary":"Renombrar / mover / archivar una categoría","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCategoryBody"}}}},"responses":{"200":{"description":"Actualizada.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Regla violada (protegida, parent inválido, grupo con hijas activas…).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"401":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"No existe para esta familia.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/scheduled-incomes":{"get":{"tags":["Me"],"summary":"Listar ingresos programados de la familia","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado ordenado por nombre","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ScheduledIncomeRow"}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear ingreso programado","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1},"amount":{"type":"number"},"frequency":{"type":"string","enum":["weekly","monthly","yearly"]},"day_of_month":{"type":"number","nullable":true},"next_due":{"type":"string","nullable":true,"pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"currency":{"type":"string"},"amount_ars":{"type":"number","nullable":true},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true}},"required":["name","amount"]}}}},"responses":{"200":{"description":"Ingreso creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScheduledIncomeRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/scheduled-incomes/{id}":{"patch":{"tags":["Me"],"summary":"Actualizar ingreso programado","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1},"amount":{"type":"number"},"frequency":{"type":"string","enum":["weekly","monthly","yearly"]},"day_of_month":{"type":"number","nullable":true},"next_due":{"type":"string","nullable":true,"pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"amount_ars":{"type":"number","nullable":true},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true}},"required":["name","amount"]}}}},"responses":{"200":{"description":"Ingreso actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScheduledIncomeRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar ingreso programado","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Eliminado","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"]}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/scheduled-incomes/{id}/register-received":{"post":{"tags":["Me"],"summary":"Marcar ingreso cobrado (tx income + avanzar next_due + audit)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"amount":{"type":"number"},"date":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"notes":{"type":"string","nullable":true}},"required":["amount","date"]}}}},"responses":{"200":{"description":"Cobro registrado","content":{"application/json":{"schema":{"type":"object","properties":{"transactionId":{"type":"string"},"nextDue":{"type":"string"}},"required":["transactionId","nextDue"]}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"409":{"description":"Conflicto: ya registrado este período o pago concurrente","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/scheduled-expenses":{"get":{"tags":["Me"],"summary":"Listar gastos programados de la familia","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado ordenado por nombre","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ScheduledExpenseRow"}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear gasto programado","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1},"amount":{"type":"number"},"frequency":{"type":"string","enum":["weekly","monthly","yearly"]},"next_due":{"type":"string","nullable":true,"pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"amount_ars":{"type":"number"},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"is_variable":{"type":"boolean"}},"required":["name","amount","frequency"]}}}},"responses":{"200":{"description":"Gasto creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScheduledExpenseRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/scheduled-expenses/{id}":{"patch":{"tags":["Me"],"summary":"Actualizar gasto programado","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1},"amount":{"type":"number"},"frequency":{"type":"string","enum":["weekly","monthly","yearly"]},"next_due":{"type":"string","nullable":true,"pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"amount_ars":{"type":"number","nullable":true},"currency":{"type":"string","nullable":true},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"is_variable":{"type":"boolean"}},"required":["name","amount","frequency"]}}}},"responses":{"200":{"description":"Gasto actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScheduledExpenseRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar gasto programado","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Eliminado","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"]}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/installments":{"get":{"tags":["Me"],"summary":"Listar cuotas/financiaciones de la familia","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado ordenado por next_due ASC","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/InstallmentRow"}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear cuota/financiación","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1},"total_amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"remaining_amount":{"type":"number","minimum":0},"installments_total":{"type":"integer","minimum":0,"exclusiveMinimum":true},"installments_paid":{"type":"integer","minimum":0},"next_due":{"type":"string","nullable":true,"pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"kind":{"type":"string","nullable":true,"enum":["loan","financing",null]},"total_amount_ars":{"type":"number","minimum":0},"remaining_amount_ars":{"type":"number","minimum":0},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true}},"required":["name","total_amount","remaining_amount","installments_total"]}}}},"responses":{"200":{"description":"Creada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstallmentRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/installments/{id}":{"patch":{"tags":["Me"],"summary":"Actualizar cuota/financiación","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"total_amount":{"type":"number","minimum":0,"exclusiveMinimum":true},"remaining_amount":{"type":"number","minimum":0},"installments_total":{"type":"integer","minimum":0,"exclusiveMinimum":true},"installments_paid":{"type":"integer","minimum":0},"next_due":{"type":"string","nullable":true,"pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"kind":{"type":"string","nullable":true,"enum":["loan","financing",null]},"total_amount_ars":{"type":"number","minimum":0},"remaining_amount_ars":{"type":"number","minimum":0},"currency":{"type":"string"},"exchange_rate":{"type":"number","nullable":true},"category_id":{"type":"string","nullable":true},"profile_id":{"type":"string","nullable":true},"account_id":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstallmentRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar cuota/financiación","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Eliminada","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"]}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/installments/{id}/register-payment":{"post":{"tags":["Me"],"summary":"Registrar un pago de cuota (incrementa pagadas, baja saldo)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Pago registrado, devuelve la cuota actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstallmentRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"409":{"description":"Conflicto: ya registrado este período o pago concurrente","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/installments/{id}/cancel-early":{"post":{"tags":["Me"],"summary":"Cancelar anticipado (saldo 0, todas las cuotas pagadas)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Cancelada, devuelve la cuota actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstallmentRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/scheduled-payments":{"get":{"tags":["Me"],"summary":"Listar audit de pagos programados (desde una fecha)","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","example":"2026-01-01"},"required":true,"name":"from","in":"query"}],"responses":{"200":{"description":"Pagos con period_month >= from, ASC","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CommitmentScheduledPaymentRow"}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Insertar audit de pago programado","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"profile_id":{"type":"string","nullable":true},"schedule_id":{"type":"string","nullable":true},"installment_id":{"type":"string","nullable":true},"scheduled_income_id":{"type":"string","nullable":true},"transaction_id":{"type":"string","nullable":true},"period_month":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"amount_ars":{"type":"number","minimum":0},"paid_date":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"notes":{"type":"string","nullable":true}},"required":["period_month","amount_ars","paid_date"]}}}},"responses":{"200":{"description":"Audit insertado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommitmentScheduledPaymentRow"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/external-debts":{"get":{"tags":["Me"],"summary":"Listar deudas externas (view con total_paid/remaining)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado ordenado por remaining DESC","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ExternalDebtStatusRow"}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear deuda externa","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"brand_id":{"type":"string"},"total_initial":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string"},"started_at":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"description":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true}},"required":["brand_id","total_initial","started_at"]}}}},"responses":{"200":{"description":"Deuda creada (row base de external_debts)","content":{"application/json":{"schema":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/commitments/external-debts/{id}":{"patch":{"tags":["Me"],"summary":"Actualizar deuda externa","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"brand_id":{"type":"string"},"total_initial":{"type":"number","minimum":0,"exclusiveMinimum":true},"currency":{"type":"string"},"started_at":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"description":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Deuda actualizada","content":{"application/json":{"schema":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Recurso no encontrado o no pertenece a la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar deuda externa","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Eliminada","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"]}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/coach/commitments":{"get":{"tags":["Me"],"summary":"Compromisos conductuales con veredicto vivo","description":"Lista los compromisos activos del caller, cada uno con su estado VIVO calculado por `evaluateCommitment` (count + sumArs de las tx del dimension target desde `period_start`, `keeping`, `daysSince`). No muta nada.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Compromisos activos con veredicto, newest-first.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CoachCommitmentVerdict"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/coach/briefings":{"get":{"tags":["Me"],"summary":"Últimos briefings del coach","description":"Devuelve los briefings diarios más recientes desde `fina_daily_insights` (fecha + texto narrativo + health score), ordenados por fecha DESC. `limit` opcional (1-30, default 7).","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":30,"example":7},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Briefings newest-first.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CoachBriefing"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/coach/vigilance":{"get":{"tags":["Me"],"summary":"Resumen de vigilancia (baselines + alertas)","description":"Devuelve los baselines de gasto top por dimensión (`spending_baselines`, ordenados por `mean_real_ars` DESC) + las últimas alertas de vigilancia (`fina_alerts` con `alert_type` de los detectores de Fase C). Read-only.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Resumen de vigilancia.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CoachVigilanceSummary"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/conversations":{"get":{"tags":["Me"],"summary":"Listar conversaciones de la familia (updated_at DESC)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado ordenado por updated_at DESC","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AiConversation"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}}}},"post":{"tags":["Me"],"summary":"Crear una conversación nueva","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateConversationBody"}}}},"responses":{"200":{"description":"Conversación creada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AiConversation"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}}}}},"/api/me/conversations/latest":{"get":{"tags":["Me"],"summary":"Obtener la conversación más reciente (o null)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"La conversación más reciente, o null si no hay ninguna","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/AiConversation"},{"nullable":true}]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}}}}},"/api/me/conversations/{id}":{"get":{"tags":["Me"],"summary":"Obtener una conversación por id","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Conversación encontrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AiConversation"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"404":{"description":"No encontrada o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}}}},"patch":{"tags":["Me"],"summary":"Actualizar messages y/o title de una conversación","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateConversationBody"}}}},"responses":{"200":{"description":"Conversación actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AiConversation"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"404":{"description":"No encontrada o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}}}},"delete":{"tags":["Me"],"summary":"Borrar una conversación","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Eliminada","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"},"id":{"type":"string"}},"required":["ok","id"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"404":{"description":"No encontrada o de otra familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationsError"}}}}}}},"/api/me/dashboard-bootstrap":{"get":{"tags":["Me"],"summary":"Dashboard bootstrap (todas las secciones en 1 request)","description":"Colapsa los ~18 GET /api/me/* del dashboard en una sola respuesta. Cada sección replica el shape de su endpoint individual para sembrar el cache de React Query sin refetch.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$","example":"2026-06"},"required":false,"name":"month","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"remindersFrom","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"remindersTo","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":500,"default":200},"required":false,"name":"txLimit","in":"query"}],"responses":{"200":{"description":"Payload con todas las secciones del dashboard","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DashboardBootstrap"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DashboardBootstrapError"}}}}}}},"/api/me/transactions-bootstrap":{"get":{"tags":["Me"],"summary":"Transactions page bootstrap (todas las secciones en 1 request)","description":"Colapsa los GET /api/me/* de la página Transacciones en una sola respuesta. Cada sección replica el shape de su endpoint individual para sembrar el cache de React Query sin refetch.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":500,"default":200},"required":false,"name":"txLimit","in":"query"}],"responses":{"200":{"description":"Payload con todas las secciones de la página Transacciones","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsBootstrap"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionsBootstrapError"}}}}}}},"/api/me/analysis-bootstrap":{"get":{"tags":["Me"],"summary":"Analysis page bootstrap (todas las secciones en 1 request)","description":"Colapsa los GET /api/me/* de la vista general de Análisis en una sola respuesta. Cada sección replica el shape de su endpoint individual para sembrar el cache de React Query sin refetch.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$","example":"2026-06"},"required":false,"name":"month","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":500,"default":200},"required":false,"name":"txLimit","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"predFrom","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"predTo","in":"query"}],"responses":{"200":{"description":"Payload con todas las secciones de la vista general de Análisis","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalysisBootstrap"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalysisBootstrapError"}}}}}}},"/api/me/recurring-predictions":{"get":{"tags":["Me"],"summary":"Predicciones de gastos recurrentes","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","example":"2026-06-05"},"required":false,"name":"from","in":"query"},{"schema":{"type":"string","example":"2026-07-05"},"required":false,"name":"to","in":"query"}],"responses":{"200":{"description":"Array de predicciones (puede ser vacío).","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{},"additionalProperties":{"nullable":true}}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/planning-bootstrap":{"get":{"tags":["Me"],"summary":"Planning page bootstrap (todas las secciones en 1 request)","description":"Colapsa los GET /api/me/* de la página Planificación en una sola respuesta. Cada sección replica el shape de su endpoint individual para sembrar el cache de React Query sin refetch.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}(-\\d{2})?$","example":"2026-06"},"required":false,"name":"month","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":500,"default":200},"required":false,"name":"txLimit","in":"query"}],"responses":{"200":{"description":"Payload con todas las secciones de la página Planificación","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlanningBootstrap"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlanningBootstrapError"}}}}}}},"/api/me/reminders":{"get":{"tags":["Me"],"summary":"Listar recordatorios de la familia","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","enum":["true","false"],"example":"false"},"required":false,"name":"completed","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","example":"2026-01-01"},"required":false,"name":"from","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","example":"2026-12-31"},"required":false,"name":"to","in":"query"}],"responses":{"200":{"description":"Listado ordenado por due_date ASC, due_time ASC (nulls last)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Reminder"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Crear un recordatorio","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReminderCreate"}}}},"responses":{"200":{"description":"Recordatorio creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Reminder"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/reminders/{id}":{"patch":{"tags":["Me"],"summary":"Actualizar un recordatorio","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReminderUpdate"}}}},"responses":{"200":{"description":"Recordatorio actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Reminder"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"No encontrado o de otra familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar un recordatorio","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Recordatorio eliminado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/reports/email":{"post":{"tags":["Me"],"summary":"Enviar un reporte financiero por email (vía Resend)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendReportInput"}}}},"responses":{"200":{"description":"Email enviado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendReportOutput"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendReportError"}}}},"403":{"description":"familyId del body no coincide con la familia del token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendReportError"}}}},"500":{"description":"Error de DB o de envío de email","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendReportError"}}}},"503":{"description":"Servidor mal configurado (RESEND_API_KEY ausente)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendReportError"}}}}}}},"/api/me/savings":{"get":{"tags":["Me"],"summary":"Lista las metas de ahorro de la familia","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Metas de ahorro ordenadas por created_at desc","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/SavingsGoal"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"post":{"tags":["Me"],"summary":"Crea una meta de ahorro","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateSavingsGoal"}}}},"responses":{"201":{"description":"Meta creada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SavingsGoal"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/savings/{id}":{"patch":{"tags":["Me"],"summary":"Edita una meta de ahorro","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateSavingsGoal"}}}},"responses":{"200":{"description":"Meta actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SavingsGoal"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Meta inexistente para la familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"delete":{"tags":["Me"],"summary":"Borra una meta de ahorro","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Meta borrada","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/family":{"get":{"tags":["Me"],"summary":"Familia del caller","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Familia","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Family"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"Familia no encontrada","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"patch":{"tags":["Me"],"summary":"Renombrar la familia","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FamilyUpdate"}}}},"responses":{"200":{"description":"Familia actualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Family"}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/family/profiles":{"get":{"tags":["Me"],"summary":"Perfiles de la familia (+ families.name)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Perfiles ordenados por full_name","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ProfileWithFamily"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/family/profiles/auth":{"get":{"tags":["Me"],"summary":"Perfiles de la familia + metadata de auth (admin)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Perfiles con email/phone/last_sign_in/MFA","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/FamilyUserWithAuth"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"403":{"description":"No admin","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/family/profiles/{id}":{"patch":{"tags":["Me"],"summary":"Editar un perfil de la familia","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProfileUpdate"}}}},"responses":{"200":{"description":"Perfil actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Profile"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"403":{"description":"Editás otro perfil sin ser admin","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"No encontrado o de otra familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/family/members":{"get":{"tags":["Me"],"summary":"Miembros de la familia","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Miembros ordenados por created_at ASC","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/FamilyMember"}}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"post":{"tags":["Me"],"summary":"Agregar un miembro a la familia","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FamilyMemberCreate"}}}},"responses":{"200":{"description":"Miembro creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FamilyMember"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"403":{"description":"No admin de la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/family/members/{id}":{"patch":{"tags":["Me"],"summary":"Editar un miembro de la familia","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FamilyMemberUpdate"}}}},"responses":{"200":{"description":"Miembro actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FamilyMember"}}}},"400":{"description":"Caller sin family_id o body inválido","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"403":{"description":"No admin de la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"404":{"description":"No encontrado o de otra familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar un miembro de la familia","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Miembro eliminado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"400":{"description":"Caller sin family_id","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"403":{"description":"No admin de la familia","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/family/avatar":{"post":{"tags":["Me"],"summary":"Subir avatar de un miembro a R2","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Avatar subido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadAvatarResponse"}}}},"400":{"description":"Caller sin family_id, multipart inválido o MIME rechazado","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"413":{"description":"Archivo excede el cap de 2 MB","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"R2 no disponible o error de upload","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/profile":{"get":{"tags":["Me"],"summary":"Profile del caller (bootstrap; reemplaza link_and_get_profile)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Profile del caller","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MeProfile"}}}},"404":{"description":"Profile no encontrado","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/alerts":{"get":{"tags":["Me"],"summary":"Alertas activas del caller","description":"Devuelve hasta 10 alertas no archivadas (`dismissed=false`) del propio perfil, ordenadas por `created_at` DESC. Mismo shape que devolvía `db.from(\"fina_alerts\")`.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado de alertas activas.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/FinaAlertRow"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/alerts/{id}/dismiss":{"patch":{"tags":["Me"],"summary":"Archivar una alerta","description":"Marca la alerta como leída/archivada (`dismissed=true` + `dismissed_at=now`). Scopeada al perfil del caller — no puede archivar alertas de otro perfil/familia.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000000"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Alerta archivada.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}},"required":["ok"]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No encontrada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/settings":{"get":{"tags":["Me"],"summary":"Preferencias de Fina del caller","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Fila de fina_settings (o null si no existe todavía)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FinaSettings"}}}},"401":{"description":"Caller sin profile","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"put":{"tags":["Me"],"summary":"Upsert de preferencias de Fina (PK profile_id)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FinaSettingsUpsert"}}}},"responses":{"200":{"description":"Preferencias guardadas (fila resultante)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FinaSettings"}}}},"401":{"description":"Caller sin profile","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/activity":{"post":{"tags":["Me"],"summary":"Registrar actividad del caller (page_view / session_start)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserActivityInsert"}}}},"responses":{"200":{"description":"Actividad registrada","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"401":{"description":"Caller sin profile","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/activity/sessions":{"get":{"tags":["Me"],"summary":"Sesiones de usuarios de la familia (admin)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado de sesiones","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/UserSessionRow"}}}}},"403":{"description":"Caller no admin","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/activity/revoke":{"post":{"tags":["Me"],"summary":"Cerrar todas las sesiones de un usuario (admin)","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RevokeSessionsBody"}}}},"responses":{"200":{"description":"Sesiones revocadas","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"403":{"description":"Caller no admin","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/client-log":{"post":{"tags":["Me"],"summary":"Registrar un log del frontend en system_logs","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClientLogInsert"}}}},"responses":{"200":{"description":"Log registrado","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}}}},"401":{"description":"Caller sin profile","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}},"/api/me/whatsapp/sessions":{"get":{"tags":["Me"],"summary":"WhatsApp sessions del family del caller","description":"Filas de `whatsapp_sessions` de la familia, con join a `profiles.full_name`. Ordenadas por `last_interaction` DESC.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado de sesiones.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppSessionRow"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/whatsapp/messages":{"get":{"tags":["Me"],"summary":"Mensajes WhatsApp recientes del family del caller","description":"Filas de `whatsapp_messages` de la familia (join a `profiles.full_name`), ordenadas por `created_at` DESC. Filtro opcional `profile_id`.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":200,"default":30},"required":false,"name":"limit","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"profile_id","in":"query"}],"responses":{"200":{"description":"Listado de mensajes.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppMessageRow"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/whatsapp/conversations":{"get":{"tags":["Me"],"summary":"Conversaciones WhatsApp agrupadas por profile (chat sidebar)","description":"Join de `whatsapp_sessions` + `profiles` con agregación de `whatsapp_messages` (último mensaje, conteo, timestamp) agrupada por `profile_id`. Scope a la familia del caller. Ordenada por `lastMessageAt` DESC. camelCase para el frontend.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Listado de conversaciones.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppConversationGroup"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/whatsapp/thread":{"get":{"tags":["Me"],"summary":"Mensajes de una conversación WhatsApp (chat viewer)","description":"Mensajes de `whatsapp_messages` de un profile dentro de la familia del caller, ordenados cronológicamente (más viejo → más nuevo) para el visor de chat. Requiere `profile_id`. Paginado por `limit`.","security":[{"bearerAuth":[]}],"parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"profile_id","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":200,"default":50},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Mensajes de la conversación.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WhatsAppThreadMessage"}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/whatsapp/last-activity":{"get":{"tags":["Me"],"summary":"Resumen de actividad WhatsApp del family del caller","description":"Badge liviano: timestamp del último mensaje, total acumulado y dirección del último. No trae bodies.","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Resumen de actividad.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WhatsAppLastActivity"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/me/push/subscribe":{"post":{"tags":["Me"],"summary":"Registrar una suscripción Web Push del dispositivo actual","description":"Guarda la `PushSubscription` (endpoint + keys p256dh/auth) asociada al perfil del caller. Idempotente por `endpoint` (UPSERT): re-suscribir el mismo navegador no duplica filas.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PushSubscribeRequest"}}}},"responses":{"200":{"description":"Suscripción guardada.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}},"required":["ok"]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}},"delete":{"tags":["Me"],"summary":"Eliminar la suscripción Web Push del dispositivo actual","description":"Borra la `PushSubscription` por `endpoint` para el perfil del caller (botón \"Desactivar en este dispositivo\" / al revocar permisos). Scoping por `profile_id` para que un perfil no pueda borrar la suscripción de otro. Idempotente: borrar algo inexistente devuelve `ok:true`.","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PushUnsubscribeRequest"}}}},"responses":{"200":{"description":"Suscripción eliminada (o no existía).","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}},"required":["ok"]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}},"500":{"description":"DB error","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}}}}}}}}}