openapi: 3.1.0
info:
  title: CPAPI English social pilot
  version: cpapi-sweepstakes.v1
  description: |
    An optional US English social profile for explicitly admitted studio builds and wallet
    sessions. Each endpoint uses the registered origin and the credential for its own
    surface and environment. The two-coin registry and catalog extension accompany this
    document. Signing, exact raw I-JSON, transaction status and idempotency inherit CPAPI v1.
    This module is a candidate and supplies no approval for a brand, title, build or territory.
tags:
  - name: Control
    description: The platform calls the registered studio endpoint.
  - name: Money
    description: The studio calls the platform Money endpoint for an admitted session.
security:
  - Signature: []
    SignatureInput: []
paths:
  /v1/sessions:
    post:
      operationId: createSocialSession
      tags: [Control]
      parameters: [ { $ref: '#/components/parameters/IdempotencyKey' } ]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: './wire.schema.json#/$defs/ControlCreate' }
      responses:
        '201':
          description: Active session. The studio echoes the requested mode, currency, locale and build.
          content:
            application/json: { schema: { $ref: './wire.schema.json#/$defs/ControlCreated' } }
        default: { $ref: '#/components/responses/Problem' }
  /v1/session-recovery:
    get:
      operationId: recoverSocialSession
      tags: [Control]
      parameters: [ { $ref: '#/components/parameters/IdempotencyKey' } ]
      responses:
        '200':
          description: Previously accepted session for the signed original key, echoing its social profile.
          content:
            application/json: { schema: { $ref: './wire.schema.json#/$defs/ControlReceipt' } }
        default: { $ref: '#/components/responses/Problem' }
  /v1/balance:
    post:
      operationId: getSocialBalance
      tags: [Money]
      requestBody:
        required: true
        content:
          application/json: { schema: { $ref: './wire.schema.json#/$defs/Balance' } }
      responses:
        '200':
          description: Balance of the selected wallet, expressed in its original minor units.
          content:
            application/json: { schema: { $ref: './wire.schema.json#/$defs/BalanceResult' } }
        default: { $ref: '#/components/responses/Problem' }
  /v1/transactions/bet:
    post:
      operationId: betSocialCoins
      tags: [Money]
      parameters: [ { $ref: '#/components/parameters/IdempotencyKey' } ]
      requestBody:
        required: true
        content:
          application/json: { schema: { $ref: './wire.schema.json#/$defs/Bet' } }
      responses:
        '201': { $ref: '#/components/responses/Result' }
        default: { $ref: '#/components/responses/Problem' }
  /v1/transactions/win:
    post:
      operationId: winSocialCoins
      tags: [Money]
      parameters: [ { $ref: '#/components/parameters/IdempotencyKey' } ]
      requestBody:
        required: true
        content:
          application/json: { schema: { $ref: './wire.schema.json#/$defs/Win' } }
      responses:
        '201': { $ref: '#/components/responses/Result' }
        default: { $ref: '#/components/responses/Problem' }
  /v1/transactions/refund:
    post:
      operationId: refundSocialBet
      tags: [Money]
      parameters: [ { $ref: '#/components/parameters/IdempotencyKey' } ]
      description: |
        Refund one committed bet in its original coin, session, player, round and amount.
        Send the original CPAPI transaction ID in bet_transaction_id. The refund has its own
        transaction ID and idempotency key. Exact replay returns its terminal receipt.
        An absent or uncommitted original, a partial amount or a mismatched binding returns
        403 session_binding_mismatch. A second refund under a fresh ID and key returns
        409 transaction_key_conflict. Reusing a key with a changed command returns
        409 idempotency_fingerprint_conflict. A definitively declined refund replays its
        declined receipt and permits a later win on the original bet. An unresolved
        refund keeps the win blocked. Read status using the original refund identity.
      requestBody:
        required: true
        content:
          application/json: { schema: { $ref: './wire.schema.json#/$defs/Refund' } }
      responses:
        '201': { $ref: '#/components/responses/Result' }
        '403': { $ref: '#/components/responses/Problem' }
        '409': { $ref: '#/components/responses/Problem' }
        default: { $ref: '#/components/responses/Problem' }
  /v1/transactions/{transaction_id}:
    get:
      operationId: readSocialTransaction
      tags: [Money]
      parameters:
        - { name: transaction_id, in: path, required: true, schema: { $ref: './wire.schema.json#/$defs/Id' } }
      responses:
        '200':
          description: Recorded transaction outcome. The amount carries its original wallet currency.
          content:
            application/json: { schema: { $ref: './wire.schema.json#/$defs/Status' } }
        default: { $ref: '#/components/responses/Problem' }
components:
  securitySchemes:
    Signature: { type: apiKey, in: header, name: Signature }
    SignatureInput: { type: apiKey, in: header, name: Signature-Input }
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      schema: { type: string, minLength: 1, maxLength: 255 }
      description: The original business key. The Control signature covers it; Money binds the typed command and journal entry under the existing Money profile.
  responses:
    Result:
      description: Terminal command result and the selected currency's balance. Replaying a committed command preserves its original receipt.
      content:
        application/json: { schema: { $ref: './wire.schema.json#/$defs/Result' } }
    Problem:
      description: CPAPI problem. A transport failure or indeterminate outcome requires status/reconciliation before any further action.
      content:
        application/problem+json: { schema: { $ref: '../../../p0/machine-schemas/schemas/problem.schema.json#/$defs/Problem' } }
