{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/oxfordledge-com/json-schema/oxfordledge-com-post-import-fetch-estimate-response-schema.json",
  "title": "PostImportFetchEstimateResponse",
  "description": "`POST /api/portfolio/post-import-fetch` — M1-1 Phase 1 quota gate.\n\nPlan: docs/board/audit/2026-05-28_CHAOS_m1_post_import_quota_gate_scoping.md\nOWNER ratifications baked in: see services/post_import_fetch.py\nmodule docstring.\n\nPhase 1 returns ONLY the estimate + the gate decision — no AI call,\nno credit decrement, no SSE stream (that's Phase 2). The FE renders\na confirm dialog from this response and POSTs the same payload to\nthe Phase 2 commit route once shipped.\n\nRequired fields (typed-client wire contract — FE deref's without\nnull-check):\n  - estimated_credits_low: charge-after-success lower bound.\n  - estimated_credits_high: low + 50% retry headroom (Q5).\n  - tickers_validated: server-side cleaned/deduped/capped list.\n  - idempotency_key: echoed back so Phase 2 can collapse retries.\n\nOptional fields cover the rejection branches — only ONE of\n`trial_locked` / `insufficient` / `monthly_cap_exceeded` /\n`too_many_tickers` is set per call. The FE branches on whichever\nis truthy and renders the matching upsell / error copy.",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/oxfordledge-com-api-openapi.yml#/components/schemas/PostImportFetchEstimateResponse",
  "properties": {
    "estimated_credits_low": {
      "type": "integer",
      "title": "Estimated Credits Low",
      "description": "Lower-bound credit charge (1 credit per validated ticker on success). FE renders this as 'will cost N credits'."
    },
    "estimated_credits_high": {
      "type": "integer",
      "title": "Estimated Credits High",
      "description": "Upper-bound credit charge — low + 50% retry headroom (per OWNER Q5 ratification 2026-05-28). FE renders this as 'up to N if retries needed'."
    },
    "tickers_validated": {
      "items": {
        "type": "string"
      },
      "type": "array",
      "title": "Tickers Validated",
      "description": "Server-validated, deduped, and capped ticker list. May be empty on rejection branches."
    },
    "idempotency_key": {
      "type": "string",
      "title": "Idempotency Key",
      "description": "Echo of the client-supplied UUID, threaded through to Phase 2 for collapse-on-retry."
    },
    "trial_locked": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Trial Locked",
      "description": "True on the plus_trial + AI-action branch (402). Per OWNER Q3 ratification 2026-05-28: trials may not consume AI features."
    },
    "insufficient": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Insufficient",
      "description": "True when credit_balance < estimated_credits_low (402). Inline upsell branch."
    },
    "monthly_cap_exceeded": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Monthly Cap Exceeded",
      "description": "True when MTD post-import spend + low > 80% of TIER_BUNDLED_CREDITS (402). Per OWNER Q8 ratification 2026-05-28."
    },
    "too_many_tickers": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Too Many Tickers",
      "description": "True when deduped ticker count > POST_IMPORT_MAX_TICKERS_PER_CALL (422). Per OWNER Q1 ratification 2026-05-28: global 25-ticker cap."
    },
    "balance": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Balance",
      "description": "Current credit balance — surfaced on the insufficient + OK branches."
    },
    "needed": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Needed",
      "description": "Credits needed to clear the lower bound — surfaced on the insufficient branch."
    },
    "monthly_cap": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Monthly Cap",
      "description": "The 80% hard cap on MTD post-import AI spend — surfaced on the monthly_cap_exceeded branch."
    },
    "monthly_spend_to_date": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Monthly Spend To Date",
      "description": "MTD post-import-AI credit spend — surfaced on the monthly_cap_exceeded branch."
    },
    "max_tickers_per_call": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Max Tickers Per Call",
      "description": "The per-call ticker cap — surfaced on the too_many_tickers branch (gives FE the exact value for the error copy)."
    },
    "submitted_count": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Submitted Count",
      "description": "Number of unique tickers the client submitted — surfaced on the too_many_tickers branch."
    },
    "upgrade_url": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Upgrade Url",
      "description": "Plan upsell URL — surfaced on the trial_locked / insufficient / monthly_cap_exceeded branches."
    },
    "message": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Message",
      "description": "Human-readable copy for the active branch. Placeholder pending VOICE+DESIGN co-pass before user-visible launch."
    },
    "decision": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Decision",
      "description": "Machine-readable decision code ('ok', 'trial_locked', 'insufficient_credits', 'monthly_cap_exceeded', 'too_many_tickers', 'bad_request'). Mirrors HTTP status."
    },
    "action": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Action",
      "description": "Echoed action type ('news' or 'research') on the OK branch."
    },
    "model": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Model",
      "description": "AI model identifier the Phase 2 fetch will use — surfaced on the OK branch so the FE can show a 'powered by' chip if desired."
    },
    "max_tokens": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Max Tokens",
      "description": "Per-ticker output-token cap the Phase 2 fetch will apply — surfaced on the OK branch."
    }
  },
  "additionalProperties": true,
  "type": "object",
  "required": [
    "estimated_credits_low",
    "estimated_credits_high",
    "tickers_validated",
    "idempotency_key"
  ]
}