openapi: 3.1.0
jsonSchemaDialect: https://spec.openapis.org/oas/3.1/dialect/base
info:
  title: NATUVISIO Circle Sovereign Partner, Attribution, Search & MCP API
  version: 4.5.0
  summary: Zero-dependency Rust partner attribution, K0–K3 KYC ladder, SHA-256/BLAKE3 ledger, 2026 GVK 20/B tax & income calculators,
    TGK compliance linter, BM25 Turkish search, and MCP 2025-06-18 server.
  description: Official OpenAPI 3.1.0 contract for `circle.natuvisio.com` (`circle-site` + `circle-core` + `nv-core`). Every
    endpoint is served both at root (`/v1/*`, `/mcp`, `/p/{code}`, `/c/{code}`, `/checkout`, `/healthz`) and under the `/api/circle`
    prefix mirror. Complies strictly with TGK 2013/49, Reklam Kurulu 2021/2 & m. 23/A, 6502 m. 80, 6197 m. 24 (pharmacy B2B
    deontology firewall), and 2026 GVK Mükerrer 20/B.
  contact:
    name: NATUVISIO GIDA TAKVİYELERİ VE TİCARET LİMİTED ŞİRKETİ
    url: https://circle.natuvisio.com
    email: partner@natuvisio.com
  license:
    name: Proprietary — NATUVISIO GIDA TAKVİYELERİ VE TİCARET LİMİTED ŞİRKETİ
    identifier: LicenseRef-NATUVISIO-Proprietary
servers:
- url: https://circle.natuvisio.com
  description: Primary Production NATUVISIO Circle Portal & Sovereign Rust API
- url: https://circle.natuvisio.com/api/circle
  description: Prefix-Stripped Circle API Mirror (`/api/circle/v1/*` -> `/v1/*`)
tags:
- name: Attribution
  description: Plug 1 & V3 first-click 60-day attribution, WKWebView `/c/{code}` capture, and 70/30 Hamilton split.
- name: Checkout & Webhooks
  description: Plug 2 store checkout attribution and HMAC-signed `order.paid` / `order.refunded` webhooks.
- name: Partner Me
  description: Plug 3 authenticated partner profile, K0–K3 KYC ladder, encrypted TR IBAN/TCKN payout account, SHA-256 ledger,
    and PII-guarded telemetry.
- name: Calculators & Compliance
  description: Deterministic 1–36m Circle commission simulator, 2026 GVK 20/B tax calculator, TGK/Reklam Kurulu copy linter,
    and QR standee SVG.
- name: Search, Graph & MCP
  description: Weighted multi-field Turkish Okapi BM25 search with TGK abstention gate, live runtime knowledge graph, and
    MCP `2025-06-18` JSON-RPC 2.0.
- name: Ops & Reconciliation
  description: Plug 4 & Plug 5 ops control plane, four-eyes `2.500 TL` payout batching, dual-secret ingest, BLAKE3 state sync,
    and 3-way zero-kuruş A2A reconciliation.
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Constant-time HMAC-SHA256 (`HS256`) JWT with mandatory `sub` and `exp` claims (`role: "ops"` or `app_metadata.role:
        "ops"` required for `/v1/ops/*`).'
    WebhookHmac:
      type: apiKey
      in: header
      name: NV-Signature
      description: 'Timestamped HMAC-SHA256 webhook signature (`t=<unix_sec>,v1=<hex_hmac_sha256>`) verified with ±300s clock-skew
        protection (edge proxy alias: `X-NV-Signature`).'
  schemas:
    ErrorResponse:
      type: object
      required:
      - error
      properties:
        error:
          type: string
          examples:
          - UNAUTHORIZED
          - FORBIDDEN_ROLE
          - BAD_SIGNATURE
          - INVALID_JSON
    ClickTelemetry:
      type: object
      required:
      - counted
      - ua_class
      - wkwebview
      - reason
      properties:
        id:
          type:
          - string
          - 'null'
          examples:
          - clk_01JDE9K8Z00000000000000065
        partner:
          type: string
          examples:
          - NVDEMO
        effective_partner:
          type: string
          examples:
          - NVDEMO
        counted:
          type: boolean
        ua_class:
          type: string
          enum:
          - human
          - preview
          - bot
        wkwebview:
          type: boolean
        reason:
          type: string
          examples:
          - ok
          - kept_first_click
          - duplicate_window
          - link_preview
          - bot
          - unknown_code
          - partner_inactive
    CheckoutAttributionResponse:
      type: object
      required:
      - cookie
      - click_id
      - status
      - result
      - order
      - commission_minor
      - flags
      properties:
        cookie:
          type: string
          enum:
          - valid
          - none
        click_id:
          type: boolean
        status:
          type: integer
          const: 200
        result:
          type: string
          enum:
          - ok
          - duplicate
          - unattributed
        order:
          type: string
        partner:
          type:
          - string
          - 'null'
        via:
          type:
          - string
          - 'null'
          enum:
          - click
          - code
          - null
        commission_minor:
          type: integer
          minimum: 0
        flags:
          type: array
          items:
            type: string
    OrderWebhookRequest:
      type: object
      required:
      - id
      - type
      - order_id
      properties:
        id:
          type: string
          description: Idempotent event identifier (`evt_...`).
        type:
          type: string
          enum:
          - order.paid
          - order.refunded
        order_id:
          type: string
        total_minor:
          type: integer
          minimum: 0
          description: Order gross total in kuruş (required for `order.paid`).
        shipping_minor:
          type: integer
          minimum: 0
          default: 0
        refund_minor:
          type: integer
          minimum: 1
          description: Refund amount in kuruş (required for `order.refunded`).
        click_id:
          type: string
        typed_code:
          type: string
        customer_hash:
          type: string
        phone_hash:
          type: string
        geo_hash:
          type: string
        iban_holder_hash:
          type: string
        card_fp_hash:
          type: string
    PartnerMeResponse:
      type: object
      required:
      - uid
      - code
      - status
      - rate_bp
      - profile
      - completeness
      - kyc
      - ledger_head
      properties:
        uid:
          type: string
        code:
          type: string
        status:
          type: string
          enum:
          - active
          - paused
        rate_bp:
          type: integer
          minimum: 1500
          maximum: 3000
        profile:
          type: object
          properties:
            first_name:
              type: string
            last_name:
              type: string
            instagram_handle:
              type: string
            city:
              type: string
            partner_type:
              type: string
            audience:
              type: string
              enum:
              - ''
              - 1-50
              - 51-500
              - 501-5000
              - 5001+
            ig_verified:
              type: boolean
            affiliations:
              type: array
              items:
                type: object
                properties:
                  kind:
                    type: string
                  name:
                    type: string
                  role:
                    type: string
                  city:
                    type: string
                  verified:
                    type: boolean
            payout:
              type:
              - object
              - 'null'
              properties:
                holder_name:
                  type: string
                last4:
                  type: string
                account_kind:
                  type: string
                tax_kind:
                  type: string
                doc_type:
                  type: string
                match:
                  type: string
        completeness:
          type: object
          properties:
            set:
              type: integer
            of:
              type: integer
              const: 5
            payout:
              type: boolean
            ig_verified:
              type: boolean
        kyc:
          type: object
          required:
          - level
          - missing
          - checks
          - unlocks
          properties:
            level:
              type: integer
              minimum: 0
              maximum: 3
            next:
              type:
              - string
              - 'null'
              enum:
              - K1
              - K2
              - K3
              - null
            missing:
              type: array
              items:
                type: string
            checks:
              type: object
              additionalProperties:
                type: boolean
            unlocks:
              type: array
              items:
                type: string
        ledger_head:
          type: string
          minLength: 64
          maxLength: 64
    ProfileUpdateRequest:
      type: object
      properties:
        first_name:
          type: string
        last_name:
          type: string
        instagram_handle:
          type: string
          maxLength: 30
        city:
          type: string
        partner_type:
          type: string
          enum:
          - diyetisyen
          - salon
          - koc
          - sporcu
          - topluluk
          - icerik
          - spa
          - klinik
          - kurumsal
        audience:
          type: string
          enum:
          - 1-50
          - 51-500
          - 501-5000
          - 5001+
    PayoutAccountRequest:
      type: object
      required:
      - holder_name
      - iban
      - tax_id
      properties:
        holder_name:
          type: string
        iban:
          type: string
          description: 26-char Turkish TR IBAN verified via ISO 13616 mod-97.
        account_kind:
          type: string
          enum:
          - standard
          - gvk20b
          default: standard
        tax_kind:
          type: string
          enum:
          - tckn
          - vkn
          default: tckn
        tax_id:
          type: string
          description: 11-digit TCKN (double checksum) or 10-digit VKN.
        doc_type:
          type: string
          enum:
          - smm
          - efatura
          - gvk20b
          - gider_pusulasi
          default: smm
    LedgerResponse:
      type: object
      required:
      - partner
      - chain_ok
      - head
      - b3
      - rows
      properties:
        partner:
          type: string
        chain_ok:
          type: boolean
        head:
          type: string
        b3:
          type: string
          minLength: 64
          maxLength: 64
        rows:
          type: array
          items:
            type: object
            required:
            - seq
            - kind
            - order
            - amount
            - prev
            - hash
            properties:
              seq:
                type: integer
                minimum: 1
              kind:
                type: string
                enum:
                - accrued
                - approved
                - reversed
                - clawback
                - paid
              order:
                type: string
              amount:
                type: integer
              prev:
                type: string
                minLength: 64
                maxLength: 64
              hash:
                type: string
                minLength: 64
                maxLength: 64
    AttributionResolveRequest:
      type: object
      required:
      - commission_pool_minor
      properties:
        order_id:
          type: string
          default: NV-SPLIT-1
        commission_pool_minor:
          type: integer
          minimum: 0
        explicit_code:
          type:
          - string
          - 'null'
        now_ms:
          type: integer
        touches:
          type: array
          items:
            type: object
            required:
            - partner_code
            properties:
              partner_code:
                type: string
              ts_ms:
                type: integer
              channel:
                type: string
                default: link
    AttributionResolveResponse:
      type: object
      required:
      - order_id
      - total_minor
      - policy
      - merkle_root
      - shares
      properties:
        order_id:
          type: string
        total_minor:
          type: integer
        policy:
          type: string
        merkle_root:
          type: string
          minLength: 64
          maxLength: 64
        shares:
          type: array
          items:
            type: object
            required:
            - partner_code
            - role
            - amount_minor
            - weight_bp
            - leaf_hash
            properties:
              partner_code:
                type: string
              role:
                type: string
              amount_minor:
                type: integer
              weight_bp:
                type: integer
              leaf_hash:
                type: string
                minLength: 64
                maxLength: 64
    IncomeCalcRequest:
      type: object
      properties:
        product:
          type: string
          enum:
          - wb
          - ox
          - duo
          default: wb
        plan:
          type: string
          enum:
          - list
          - member
          - sub
          default: list
        price_try:
          type: integer
          minimum: 1
        partner_type:
          type: string
          default: diyetisyen
        base_rate_pct:
          type: integer
          minimum: 15
          maximum: 30
        new_per_month:
          type: number
          minimum: 0
          maximum: 5000
          default: 5.0
        reorder_pct:
          type: number
          minimum: 0
          maximum: 100
          default: 40.0
        refund_pct:
          type: number
          minimum: 0
          maximum: 100
          default: 3.0
        months:
          type: integer
          minimum: 1
          maximum: 36
          default: 12
    IncomeCalcResponse:
      type: object
      required:
      - product
      - plan
      - price_try
      - base_minor
      - base_rate_pct
      - rate_cap_pct
      - min_payout_minor
      - cycle_months
      - total_12m_minor
      - total_12m_try
      - one_time_12m_minor
      - pricing_catalog
      - tiers
      - months
      properties:
        product:
          type: string
          enum:
          - wb
          - ox
          - duo
        plan:
          type: string
          enum:
          - list
          - member
          - sub
        price_try:
          type: integer
        base_minor:
          type: integer
        base_rate_pct:
          type: integer
        rate_cap_pct:
          type: integer
          const: 30
        min_payout_minor:
          type: integer
          const: 250000
          description: 2.500 TL minimum payout threshold in kuruş.
        cycle_months:
          type: integer
          enum:
          - 1
          - 2
          description: Refill cycle (`2` for Wellbeing & Duo 59d, `1` for Oxifit 29d).
        total_12m_minor:
          type: integer
        total_12m_try:
          type: number
        one_time_12m_minor:
          type: integer
        pricing_catalog:
          type: object
        tiers:
          type: array
          items:
            type: object
        months:
          type: array
          items:
            type: object
            required:
            - month
            - new_orders
            - reorders
            - approved_orders
            - tier
            - rate_pct
            - per_order_minor
            - month_minor
            - cum_minor
            - carry_forward_minor
            - payout_minor
            - payout_eligible
            properties:
              month:
                type: integer
              new_orders:
                type: number
              reorders:
                type: number
              approved_orders:
                type: number
              tier:
                type: string
                enum:
                - Tohum
                - Kök
                - Ağaç
                - Taç
              rate_pct:
                type: integer
              per_order_minor:
                type: integer
              month_minor:
                type: integer
              cum_minor:
                type: integer
              carry_forward_minor:
                type: integer
              payout_minor:
                type: integer
              payout_eligible:
                type: boolean
    TaxCalcRequest:
      type: object
      required:
      - annual_gross_try
      properties:
        annual_gross_try:
          type: number
          minimum: 0
        annual_gross_minor:
          type: integer
          minimum: 0
        is_bagkur_exempt:
          type: boolean
          default: false
        mode:
          type: string
          enum:
          - gvk20b
          - smm
          - fatura
          default: gvk20b
    TaxCalcResponse:
      type: object
      required:
      - annual_gross_try
      - mode
      - gvk_20b_cap_try
      - within_20b_cap
      - withholding_15pct_try
      - net_20b_try
      - cliff_breach_warning
      - is_bagkur_exempt
      - bagkur_alert
      - bagkur_note
      - estimated_progressive_tax_try
      - store_credit_115_try
      properties:
        annual_gross_try:
          type: number
        mode:
          type: string
        gvk_20b_cap_try:
          type: number
          const: 5300000.0
        within_20b_cap:
          type: boolean
        withholding_15pct_try:
          type: number
        net_20b_try:
          type: number
        cliff_breach_warning:
          type: boolean
        is_bagkur_exempt:
          type: boolean
        bagkur_alert:
          type: boolean
        bagkur_note:
          type: string
        estimated_progressive_tax_try:
          type: number
        store_credit_115_try:
          type: number
    ComplianceLintRequest:
      type: object
      required:
      - text
      properties:
        text:
          type: string
          description: Draft social media caption, blog paragraph, or partner copy in Turkish.
    ComplianceLintResponse:
      type: object
      required:
      - compliant
      - has_disclosure
      - health_violations
      - income_violations
      properties:
        compliant:
          type: boolean
        has_disclosure:
          type: boolean
        health_violations:
          type: array
          items:
            type: string
        income_violations:
          type: array
          items:
            type: string
    ReconcileA2AResponse:
      type: object
      required:
      - status
      - orders_net_minor
      - gateway_net_minor
      - ledger_net_minor
      - paid_minor
      - drift_minor
      - approved_minor
      - pending_minor
      - held_minor
      - unsettled_clawback_minor
      - chain_ok
      - b3
      properties:
        status:
          type: string
          enum:
          - MATCH
          - DRIFT
        orders_net_minor:
          type: integer
        gateway_net_minor:
          type: integer
        ledger_net_minor:
          type: integer
        paid_minor:
          type: integer
        drift_minor:
          type: integer
        approved_minor:
          type: integer
        pending_minor:
          type: integer
        held_minor:
          type: integer
        unsettled_clawback_minor:
          type: integer
        chain_ok:
          type: boolean
        b3:
          type: string
          minLength: 64
          maxLength: 64
    SearchResponse:
      type: object
      required:
      - schema_version
      - query
      - normalized_query
      - total_docs
      - count
      - took_us
      - abstention
      - facets
      - hits
      properties:
        schema_version:
          type: integer
          const: 1
        query:
          type: string
        normalized_query:
          type: string
        total_docs:
          type: integer
        count:
          type: integer
        took_us:
          type: integer
        abstention:
          type: object
          required:
          - triggered
          - rule_id
          - safe_notice_tr
          - recommended_compliance_url
          properties:
            triggered:
              type: boolean
            rule_id:
              type: string
            safe_notice_tr:
              type: string
            recommended_compliance_url:
              type: string
              const: /bilgi/tgk-ve-reklam-kurulu-uyumu/
        facets:
          type: object
          properties:
            doc_type:
              type: object
              additionalProperties:
                type: integer
            city_plaka:
              type: object
              additionalProperties:
                type: integer
            segment:
              type: object
              additionalProperties:
                type: integer
        hits:
          type: array
          items:
            type: object
            required:
            - id
            - title
            - url
            - doc_type
            - description
            - score
            - city_plaka
            properties:
              id:
                type: string
              title:
                type: string
              url:
                type: string
              doc_type:
                type: string
              description:
                type: string
              score:
                type: number
              city_plaka:
                type: string
    GraphResponse:
      type: object
      required:
      - schema_version
      - nodes
      - edges
      - ledger_b3
      - partner_count
      - events_count
      - wire_files_count
      - search_docs_count
      properties:
        schema_version:
          type: integer
          const: 1
        ledger_b3:
          type: string
          minLength: 64
          maxLength: 64
        partner_count:
          type: integer
        events_count:
          type: integer
        wire_files_count:
          type: integer
        search_docs_count:
          type: integer
        counts:
          type: object
        nodes:
          type: array
          items:
            type: object
        edges:
          type: array
          items:
            type: object
paths:
  /p/{code}:
    get:
      operationId: redirectPartnerLink
      tags:
      - Attribution
      summary: First-click 60-day partner attribution redirect (`/p/{code}`)
      description: Normalizes partner code, filters link previews/bots, enforces 60-day `first_click` attribution, issues
        signed `HttpOnly; SameSite=Lax` cookies (`nv_ref` & `nv_circle_ref`, `Max-Age=5184000`), and 302-redirects (or returns
        JSON when `?json=1`).
      parameters:
      - name: code
        in: path
        required: true
        schema:
          type: string
          example: NVDEMO
      - name: ch
        in: query
        required: false
        schema:
          type: string
          default: link
          example: ig
      - name: json
        in: query
        required: false
        schema:
          type: string
          enum:
          - '0'
          - '1'
      responses:
        '200':
          description: JSON click telemetry returned when `?json=1`.
          headers:
            X-Circle-Click:
              schema:
                type: string
            Set-Cookie:
              schema:
                type: string
              description: Signed 60d `nv_ref` and `nv_circle_ref` `HttpOnly; SameSite=Lax` cookies.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClickTelemetry'
        '302':
          description: Redirects to `/?ref={effective_code}&ch={ch}&nv_clk={clk_id}` with 60-day `nv_ref` & `nv_circle_ref`
            cookies.
          headers:
            Location:
              schema:
                type: string
            X-Circle-Click:
              schema:
                type: string
            Set-Cookie:
              schema:
                type: string
  /c/{code}:
    get:
      operationId: captureWkWebViewClick
      tags:
      - Attribution
      summary: Same-origin WKWebView & QR capture redirect (`/c/{code}`)
      description: 'Same-origin first-party cookie & S2S click capture designed for Instagram/TikTok in-app `WKWebView` browsers
        and CGNAT mobile networks. Emits `X-Circle-WKWebView: 1` when an in-app webview UA is detected and sets signed 60-day
        `nv_ref` and `nv_circle_ref` `HttpOnly; SameSite=Lax` cookies.'
      parameters:
      - name: code
        in: path
        required: true
        schema:
          type: string
          example: NVDEMO
      - name: ch
        in: query
        required: false
        schema:
          type: string
          default: link
          example: qr
      - name: json
        in: query
        required: false
        schema:
          type: string
          enum:
          - '0'
          - '1'
      responses:
        '200':
          description: JSON click capture telemetry when `?json=1`.
          headers:
            X-Circle-Click:
              schema:
                type: string
            X-Circle-WKWebView:
              schema:
                type: string
                enum:
                - '1'
            Set-Cookie:
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClickTelemetry'
        '302':
          description: 302 redirect to store landing with `nv_ref` & `nv_circle_ref` 60-day cookies.
          headers:
            Location:
              schema:
                type: string
            X-Circle-Click:
              schema:
                type: string
            X-Circle-WKWebView:
              schema:
                type: string
                enum:
                - '1'
            Set-Cookie:
              schema:
                type: string
  /checkout:
    get:
      operationId: resolveStoreCheckout
      tags:
      - Checkout & Webhooks
      summary: Store checkout attribution resolver & `order.paid` emitter (Plug 2)
      description: Evaluates signed `nv_circle_ref` / `nv_ref` 60-day cookies and optional typed `code`, checks partner active
        status and `G_SELF` self-referral guard, appends SHA-256 ledger row, and returns HTML or JSON (`?format=json`).
      parameters:
      - name: order
        in: query
        schema:
          type: string
          default: NV-30001
      - name: total
        in: query
        schema:
          type: integer
          default: 680000
      - name: code
        in: query
        schema:
          type: string
      - name: customer_hash
        in: query
        schema:
          type: string
      - name: format
        in: query
        schema:
          type: string
          enum:
          - html
          - json
      responses:
        '200':
          description: Attribution outcome and accrued commission in kuruş.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckoutAttributionResponse'
            text/html:
              schema:
                type: string
  /v1/webhooks/orders:
    post:
      operationId: ingestOrderWebhook
      tags:
      - Checkout & Webhooks
      summary: Inbound HMAC-signed `order.paid` & `order.refunded` webhook
      security:
      - WebhookHmac: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderWebhookRequest'
      responses:
        '200':
          description: Idempotent order accrual, duplicate suppression, or proportional refund reversal/clawback.
          content:
            application/json:
              schema:
                type: object
        '202':
          description: Out-of-order `order.refunded` parked until corresponding `order.paid` arrives.
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Invalid or expired `NV-Signature`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Malformed event payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/me:
    get:
      operationId: getPartnerMe
      tags:
      - Partner Me
      summary: Get authenticated partner profile, completeness & K0–K3 KYC state
      security:
      - BearerAuth: []
      responses:
        '200':
          description: Partner profile and KYC state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerMeResponse'
        '401':
          description: Missing, forged, or expired HS256 JWT.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Partner UID not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/me/profile:
    put:
      operationId: updatePartnerProfile
      tags:
      - Partner Me
      summary: Update partner profile fields & recalculate K0–K3 KYC level
      security:
      - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProfileUpdateRequest'
      responses:
        '200':
          description: Updated partner state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerMeResponse'
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation error or `MASS_ASSIGNMENT_REFUSED`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/me/payout-account:
    put:
      operationId: updatePayoutAccount
      tags:
      - Partner Me
      summary: Save encrypted TR IBAN & TCKN/VKN payout account (`last4` returned)
      security:
      - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PayoutAccountRequest'
      responses:
        '200':
          description: Saved encrypted payout account and updated KYC level.
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: '`IBAN_CHECKSUM`, `TCKN_CHECKSUM`, or `GVK20B_DOC_MISMATCH`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/me/ledger:
    get:
      operationId: getPartnerLedger
      tags:
      - Partner Me
      summary: Verify and return partner SHA-256 hash-chained ledger & BLAKE3 digest
      security:
      - BearerAuth: []
      responses:
        '200':
          description: Verified hash-chained ledger.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerResponse'
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/telemetry:
    post:
      operationId: ingestPartnerTelemetry
      tags:
      - Partner Me
      summary: Ingest PII-guarded partner PWA telemetry event or batch (`<= 50`)
      security:
      - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: string
                type:
                  type: string
                events:
                  type: array
                  maxItems: 50
                  items:
                    type: object
      responses:
        '202':
          description: Telemetry accepted.
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized in production.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: '`PII_IN_TELEMETRY` or `BATCH_TOO_LARGE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/attribution/resolve:
    post:
      operationId: resolveMultiTouchAttribution
      tags:
      - Attribution
      summary: Multi-influencer 70/30 attribution split with Hamilton kuruş conservation & Merkle root
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AttributionResolveRequest'
      responses:
        '200':
          description: Exact integer kuruş allocation and SHA-256 Merkle root.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttributionResolveResponse'
        '400':
          description: Invalid JSON.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/calc/income:
    post:
      operationId: calculatePartnerIncome
      tags:
      - Calculators & Compliance
      summary: Deterministic 1–36m Circle commission, refill cohort (`cycle=2`) & `2.500 TL` payout threshold simulator
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IncomeCalcRequest'
      responses:
        '200':
          description: Month-by-month simulation across Tohum, Kök, Ağaç, and Taç tiers.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IncomeCalcResponse'
        '400':
          description: Invalid JSON.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/calc/tax:
    post:
      operationId: calculateTurkishTax2026
      tags:
      - Calculators & Compliance
      summary: 2026 GVK Mükerrer 20/B (`5.300.000 TL` cap, 15% stopaj), Law 7566 Bağ-Kur & `1.15x` store credit calculator
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TaxCalcRequest'
      responses:
        '200':
          description: 2026 Turkish partner tax & withholding comparison report.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaxCalcResponse'
        '400':
          description: Invalid JSON.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/compliance/lint:
    post:
      operationId: lintPartnerCopy
      tags:
      - Calculators & Compliance
      summary: TGK 2013/49 + Reklam Kurulu 2021/2 & m. 23/A partner copy linter
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ComplianceLintRequest'
      responses:
        '200':
          description: Compliance verdict, disclosure check, and violation arrays.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ComplianceLintResponse'
        '400':
          description: Invalid JSON.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/qr/standee.svg:
    get:
      operationId: renderStandeeQrSvg
      tags:
      - Calculators & Compliance
      summary: Generate print-ready ISO/IEC 18004 QR table standee SVG (`https://circle.natuvisio.com/c/{CODE}`)
      parameters:
      - name: code
        in: query
        required: false
        schema:
          type: string
          default: NVDEMO
      responses:
        '200':
          description: Vector SVG standee with TGK 2013/49 notice.
          content:
            image/svg+xml:
              schema:
                type: string
        '422':
          description: '`INVALID_CODE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/reconcile/a2a:
    get:
      operationId: reconcileThreeWayA2A
      tags:
      - Ops & Reconciliation
      summary: 3-way zero-kuruş drift reconciliation across orders, gateway & SHA-256/BLAKE3 ledgers
      responses:
        '200':
          description: '`MATCH` — zero kuruş drift and valid hash chains.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReconcileA2AResponse'
        '503':
          description: '`DRIFT` — non-zero kuruş drift or broken chain detected.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReconcileA2AResponse'
  /v1/search:
    get:
      operationId: searchPartnerCorpus
      tags:
      - Search, Graph & MCP
      summary: Weighted multi-field Turkish Okapi BM25 search with stemmer, synonyms & TGK abstention gate
      parameters:
      - name: q
        in: query
        required: false
        schema:
          type: string
          default: ''
      - name: type
        in: query
        required: false
        schema:
          type: string
          enum:
          - sayfa
          - program
          - is-ortakligi
          - eczane
          - arac
          - bilgi
          - rehber
          - sehir
          - sozluk
      - name: city
        in: query
        required: false
        schema:
          type: string
          description: Province plate `01`–`81` or city slug (`istanbul`, `ankara`).
      - name: segment
        in: query
        required: false
        schema:
          type: string
      - name: limit
        in: query
        required: false
        schema:
          type: integer
          minimum: 1
          maximum: 50
          default: 20
      responses:
        '200':
          description: Ranked hits, facet counts, and TGK abstention envelope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
  /v1/graph:
    get:
      operationId: getRuntimeSiteGraph
      tags:
      - Search, Graph & MCP
      summary: Machine-state site knowledge graph merged with live BLAKE3 ledger & wire telemetry
      responses:
        '200':
          description: Merged site-graph nodes/edges and live runtime counters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GraphResponse'
  /mcp:
    get:
      operationId: discoverMcpServer
      tags:
      - Search, Graph & MCP
      summary: MCP `2025-06-18` Streamable HTTP server card & tool manifest discovery
      responses:
        '200':
          description: MCP server metadata and 5 deterministic tool schemas.
          content:
            application/json:
              schema:
                type: object
    post:
      operationId: invokeMcpJsonRpc
      tags:
      - Search, Graph & MCP
      summary: MCP `2025-06-18` JSON-RPC 2.0 endpoint (`initialize`, `ping`, `tools/list`, `tools/call`)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - jsonrpc
              - method
              properties:
                jsonrpc:
                  type: string
                  const: '2.0'
                id:
                  type:
                  - string
                  - integer
                  - 'null'
                method:
                  type: string
                  enum:
                  - initialize
                  - ping
                  - tools/list
                  - tools/call
                  - notifications/initialized
                params:
                  type: object
      responses:
        '200':
          description: JSON-RPC 2.0 result or structured error envelope.
          content:
            application/json:
              schema:
                type: object
        '202':
          description: Accepted JSON-RPC notification without `id`.
          content:
            application/json:
              schema:
                type: object
  /v1/ops/who:
    get:
      operationId: opsVenueConflicts
      tags:
      - Ops & Reconciliation
      summary: Ops shared-venue conflict & multi-partner intelligence (Plug 4)
      security:
      - BearerAuth: []
      responses:
        '200':
          description: '`VENUE_SHARED` risk flags.'
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: '`FORBIDDEN_ROLE` (requires `ops`).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/ops/partners/{uid}/verify:
    post:
      operationId: opsVerifyPartner
      tags:
      - Ops & Reconciliation
      summary: Ops verification of partner Instagram handle or venue affiliation
      security:
      - BearerAuth: []
      parameters:
      - name: uid
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                what:
                  type: string
                  enum:
                  - instagram
                  - affiliation
                  default: instagram
      responses:
        '200':
          description: Updated KYC level and unlocks.
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: '`FORBIDDEN_ROLE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Partner UID not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/ops/hold-elapsed:
    post:
      operationId: opsApproveHoldElapsed
      tags:
      - Ops & Reconciliation
      summary: Approve pending commission after 14-day withdrawal period (`6502` m. 48)
      security:
      - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - order_id
              properties:
                order_id:
                  type: string
      responses:
        '200':
          description: '`approved` or `noop`.'
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: '`FORBIDDEN_ROLE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: '`MISSING_ORDER_ID`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/ops/payouts/draft:
    post:
      operationId: opsDraftPayoutBatch
      tags:
      - Ops & Reconciliation
      summary: Draft payout batch for K2+ partners (`>= 250.000` kuruş / `2.500 TL`) with carry-forward
      security:
      - BearerAuth: []
      responses:
        '200':
          description: Draft batch ID, eligible items, and `below_min_payout` carry-forward list.
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: '`FORBIDDEN_ROLE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/ops/payouts/{id}/approve:
    post:
      operationId: opsApprovePayoutBatch
      tags:
      - Ops & Reconciliation
      summary: Four-eyes payout batch approval (`approver != drafter`)
      security:
      - BearerAuth: []
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Settled payout batch and appended `paid` ledger rows.
          content:
            application/json:
              schema:
                type: object
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: '`FOUR_EYES_REQUIRED` or `FORBIDDEN_ROLE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Batch not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: '`ALREADY_PROCESSED`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/ingest:
    post:
      operationId: opsIngestEvent
      tags:
      - Ops & Reconciliation
      summary: Ops webhook receiver with dual-secret rotation & ±300s clock-skew guard (Plug 5)
      security:
      - WebhookHmac: []
      parameters:
      - name: NV-Event-Id
        in: header
        required: false
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - id
              properties:
                id:
                  type: string
                type:
                  type: string
      responses:
        '200':
          description: 'Ingested event (`duplicate: false|true`).'
          content:
            application/json:
              schema:
                type: object
        '400':
          description: '`ID_MISMATCH`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: '`BAD_SIGNATURE`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: '`CONTRACT_VIOLATION`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /v1/state:
    get:
      operationId: getOpsSyncState
      tags:
      - Ops & Reconciliation
      summary: Ops projected partner state & BLAKE3 equivalence proof (`circle_b3 == ops_b3`)
      responses:
        '200':
          description: Projected balances and BLAKE3 sync proof.
          content:
            application/json:
              schema:
                type: object
  /healthz:
    get:
      operationId: checkHealthAndLedgerInvariants
      tags:
      - Ops & Reconciliation
      summary: Verify SHA-256 ledger hash chains, BLAKE3 state digest & outbox health
      responses:
        '200':
          description: '`complete` — all ledger hash chains verified.'
          content:
            application/json:
              schema:
                type: object
        '503':
          description: '`halted` — ledger chain invariant broken.'
          content:
            application/json:
              schema:
                type: object
