{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:aggregator-gg:cpapi:sweepstakes:v1",
  "title": "CPAPI US English social contract",
  "description": "Select a named schema under $defs. Minor units are original JSON integer tokens. Use the ordinary CPAPI signed-I-JSON and idempotency rules. Control requests go to the studio. The studio sends Money requests to Core.",
  "$defs": {
    "Id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,128}$",
      "minLength": 1,
      "maxLength": 128
    },
    "Coin": {
      "type": "string",
      "enum": [
        "SC",
        "GC"
      ]
    },
    "Build": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$",
      "minLength": 64,
      "maxLength": 64
    },
    "Environment": {
      "enum": [
        "certification",
        "live"
      ]
    },
    "Declaration": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile",
        "build_sha256",
        "countries"
      ],
      "properties": {
        "profile": {
          "const": "cpapi-sweepstakes.v1"
        },
        "build_sha256": {
          "$ref": "#/$defs/Build"
        },
        "countries": {
          "const": [
            "US"
          ]
        }
      }
    },
    "CatalogTitleExtension": {
      "type": "object",
      "required": [
        "sweepstakes",
        "supported_currencies",
        "languages"
      ],
      "properties": {
        "sweepstakes": {
          "$ref": "#/$defs/Declaration"
        },
        "supported_currencies": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string"
          },
          "contains": {
            "$ref": "#/$defs/Coin"
          }
        },
        "languages": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string"
          },
          "contains": {
            "const": "sc_en"
          }
        },
        "blocked_countries": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Z]{2}$"
          },
          "not": {
            "contains": {
              "const": "US"
            }
          }
        }
      },
      "description": "Apply to a complete v1 catalog title. Ordinary required fields and all catalog validation still apply."
    },
    "ControlCreate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_id",
        "integration_id",
        "environment",
        "player_ref",
        "game_id",
        "mode",
        "currency",
        "locale",
        "build_sha256"
      ],
      "properties": {
        "tenant_id": {
          "$ref": "#/$defs/Id"
        },
        "integration_id": {
          "$ref": "#/$defs/Id"
        },
        "environment": {
          "$ref": "#/$defs/Environment"
        },
        "player_ref": {
          "$ref": "#/$defs/Id"
        },
        "game_id": {
          "$ref": "#/$defs/Id"
        },
        "mode": {
          "const": "sweepstakes"
        },
        "currency": {
          "$ref": "#/$defs/Coin"
        },
        "locale": {
          "const": "sc_en"
        },
        "build_sha256": {
          "$ref": "#/$defs/Build"
        }
      }
    },
    "ControlReceipt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "session_id",
        "state",
        "environment",
        "mode",
        "currency",
        "locale",
        "build_sha256"
      ],
      "properties": {
        "session_id": {
          "$ref": "#/$defs/Id"
        },
        "provider_session_ref": {
          "$ref": "#/$defs/Id"
        },
        "state": {
          "enum": [
            "active",
            "expired",
            "closed"
          ]
        },
        "environment": {
          "$ref": "#/$defs/Environment"
        },
        "launch_url": {
          "type": "string",
          "format": "uri",
          "maxLength": 2048
        },
        "mode": {
          "const": "sweepstakes"
        },
        "currency": {
          "$ref": "#/$defs/Coin"
        },
        "locale": {
          "const": "sc_en"
        },
        "build_sha256": {
          "$ref": "#/$defs/Build"
        }
      },
      "if": {
        "properties": {
          "state": {
            "const": "active"
          }
        }
      },
      "then": {
        "required": [
          "launch_url"
        ]
      }
    },
    "ControlCreated": {
      "allOf": [
        {
          "$ref": "#/$defs/ControlReceipt"
        },
        {
          "properties": {
            "state": {
              "const": "active"
            }
          }
        }
      ]
    },
    "Amount": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "currency",
        "amount_minor"
      ],
      "properties": {
        "currency": {
          "$ref": "#/$defs/Coin"
        },
        "amount_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      }
    },
    "PositiveAmount": {
      "allOf": [
        {
          "$ref": "#/$defs/Amount"
        },
        {
          "properties": {
            "amount_minor": {
              "minimum": 1
            }
          }
        }
      ]
    },
    "Balance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_id",
        "integration_id",
        "environment",
        "player_ref",
        "session_id",
        "currency"
      ],
      "properties": {
        "tenant_id": {
          "$ref": "#/$defs/Id"
        },
        "integration_id": {
          "$ref": "#/$defs/Id"
        },
        "environment": {
          "$ref": "#/$defs/Environment"
        },
        "player_ref": {
          "$ref": "#/$defs/Id"
        },
        "session_id": {
          "$ref": "#/$defs/Id"
        },
        "currency": {
          "$ref": "#/$defs/Coin"
        }
      }
    },
    "BalanceResult": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "balance"
      ],
      "properties": {
        "balance": {
          "$ref": "#/$defs/Amount"
        },
        "as_of": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "Bet": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_id",
        "integration_id",
        "environment",
        "player_ref",
        "session_id",
        "round_id",
        "transaction_id",
        "amount"
      ],
      "properties": {
        "tenant_id": {
          "$ref": "#/$defs/Id"
        },
        "integration_id": {
          "$ref": "#/$defs/Id"
        },
        "environment": {
          "$ref": "#/$defs/Environment"
        },
        "player_ref": {
          "$ref": "#/$defs/Id"
        },
        "session_id": {
          "$ref": "#/$defs/Id"
        },
        "round_id": {
          "$ref": "#/$defs/Id"
        },
        "transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "amount": {
          "$ref": "#/$defs/PositiveAmount"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time"
        },
        "provider_transaction_ref": {
          "$ref": "#/$defs/Id"
        }
      }
    },
    "Win": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_id",
        "integration_id",
        "environment",
        "player_ref",
        "session_id",
        "round_id",
        "transaction_id",
        "amount",
        "bet_transaction_id"
      ],
      "properties": {
        "tenant_id": {
          "$ref": "#/$defs/Id"
        },
        "integration_id": {
          "$ref": "#/$defs/Id"
        },
        "environment": {
          "$ref": "#/$defs/Environment"
        },
        "player_ref": {
          "$ref": "#/$defs/Id"
        },
        "session_id": {
          "$ref": "#/$defs/Id"
        },
        "round_id": {
          "$ref": "#/$defs/Id"
        },
        "transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "amount": {
          "$ref": "#/$defs/Amount"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time"
        },
        "bet_transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "provider_transaction_ref": {
          "$ref": "#/$defs/Id"
        }
      }
    },
    "Refund": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_id",
        "integration_id",
        "environment",
        "player_ref",
        "session_id",
        "round_id",
        "transaction_id",
        "amount",
        "bet_transaction_id"
      ],
      "properties": {
        "tenant_id": {
          "$ref": "#/$defs/Id"
        },
        "integration_id": {
          "$ref": "#/$defs/Id"
        },
        "environment": {
          "$ref": "#/$defs/Environment"
        },
        "player_ref": {
          "$ref": "#/$defs/Id"
        },
        "session_id": {
          "$ref": "#/$defs/Id"
        },
        "round_id": {
          "$ref": "#/$defs/Id"
        },
        "transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "amount": {
          "$ref": "#/$defs/PositiveAmount"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time"
        },
        "bet_transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "provider_transaction_ref": {
          "$ref": "#/$defs/Id"
        }
      },
      "description": "One full reversal of the identified committed debit in the same tenant, integration, environment, player, session, round and currency. Use a fresh transaction ID. Replay the original only after a known terminal result."
    },
    "Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transaction_id",
        "outcome",
        "outcome_finality",
        "balance"
      ],
      "properties": {
        "transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "outcome": {
          "enum": [
            "committed",
            "declined"
          ]
        },
        "outcome_finality": {
          "const": "terminal"
        },
        "outcome_reason": {
          "type": "string",
          "maxLength": 128
        },
        "balance": {
          "$ref": "#/$defs/Amount"
        },
        "status_url": {
          "type": "string",
          "format": "uri-reference"
        }
      },
      "if": {
        "properties": {
          "outcome": {
            "const": "declined"
          }
        }
      },
      "then": {
        "required": [
          "outcome_reason"
        ]
      }
    },
    "Outcome": {
      "type": "string",
      "enum": [
        "committed",
        "declined",
        "pending",
        "indeterminate",
        "reconciliation_required",
        "reconciled_declined_remainder"
      ]
    },
    "OutcomeFinality": {
      "type": "string",
      "enum": [
        "terminal",
        "non-terminal"
      ]
    },
    "OutcomeFinalityPairing": {
      "description": "Allowed outcome x finality pairs (ADR-004 v2 §5): committed->terminal, declined->terminal, reconciled_declined_remainder->terminal, pending->non-terminal, indeterminate->non-terminal, reconciliation_required->non-terminal (strictly). Apply with allOf to any object carrying outcome + outcome_finality; any other combination MUST fail validation.",
      "oneOf": [
        {
          "required": [
            "outcome",
            "outcome_finality"
          ],
          "properties": {
            "outcome": {
              "const": "committed"
            },
            "outcome_finality": {
              "const": "terminal"
            }
          }
        },
        {
          "required": [
            "outcome",
            "outcome_finality"
          ],
          "properties": {
            "outcome": {
              "const": "declined"
            },
            "outcome_finality": {
              "const": "terminal"
            }
          }
        },
        {
          "required": [
            "outcome",
            "outcome_finality"
          ],
          "properties": {
            "outcome": {
              "const": "reconciled_declined_remainder"
            },
            "outcome_finality": {
              "const": "terminal"
            }
          }
        },
        {
          "required": [
            "outcome",
            "outcome_finality"
          ],
          "properties": {
            "outcome": {
              "const": "pending"
            },
            "outcome_finality": {
              "const": "non-terminal"
            }
          }
        },
        {
          "required": [
            "outcome",
            "outcome_finality"
          ],
          "properties": {
            "outcome": {
              "const": "indeterminate"
            },
            "outcome_finality": {
              "const": "non-terminal"
            }
          }
        },
        {
          "required": [
            "outcome",
            "outcome_finality"
          ],
          "properties": {
            "outcome": {
              "const": "reconciliation_required"
            },
            "outcome_finality": {
              "const": "non-terminal"
            }
          }
        }
      ]
    },
    "Status": {
      "description": "Recorded transaction state — the reconciliation-flow surface. This is the ONLY certification-slice schema that carries the full closed outcome vocabulary: non-terminal states (pending, indeterminate, reconciliation_required) and the terminal reconciliation outcome reconciled_declined_remainder legitimately appear here and never in a synchronous 201 (ADR-004 v2 §5). A recorded declined outcome carries its stable named reason.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transaction_id",
        "outcome",
        "outcome_finality",
        "amount"
      ],
      "allOf": [
        {
          "$ref": "#/$defs/OutcomeFinalityPairing"
        },
        {
          "if": {
            "required": [
              "outcome"
            ],
            "properties": {
              "outcome": {
                "const": "declined"
              }
            }
          },
          "then": {
            "required": [
              "outcome_reason"
            ]
          }
        }
      ],
      "properties": {
        "transaction_id": {
          "$ref": "#/$defs/Id"
        },
        "outcome": {
          "$ref": "#/$defs/Outcome"
        },
        "outcome_finality": {
          "$ref": "#/$defs/OutcomeFinality"
        },
        "outcome_reason": {
          "type": "string",
          "maxLength": 128
        },
        "amount": {
          "$ref": "#/$defs/Amount"
        },
        "recorded_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}
