{
  "openapi": "3.0.3",
  "info": {
    "title": "AS Tech API",
    "version": "1.0.0",
    "description": "Intelligent Gaming Infrastructure — real-time betting APIs with multi-duration rounds (30s, 1m, 3m, 5m, 10m), atomic wallet settlement, and a full developer key system.",
    "contact": {
      "name": "AS Tech API Support",
      "email": "support@astech.dev"
    }
  },
  "servers": [
    {
      "url": "https://sametrend.astechigaming.shop",
      "description": "Live"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Wingo",
      "description": "Multi-duration color-number rounds."
    },
    {
      "name": "K3",
      "description": "3-dice lottery (sum / size / parity)."
    },
    {
      "name": "5D",
      "description": "5-digit lottery with size markets."
    },
    {
      "name": "TRX",
      "description": "Provably-fair hash-based number-and-color game."
    },
    {
      "name": "MOTO",
      "description": "8-bike race; bet the winner."
    }
  ],
  "paths": {
    "/api/public/v1/wingo/state": {
      "get": {
        "tags": [
          "Wingo"
        ],
        "summary": "Get live round state",
        "description": "Returns all currently open rounds (one per duration) plus the most recent settled history. Pass `?duration=` to filter.",
        "parameters": [
          {
            "name": "duration",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                30,
                60,
                180,
                300,
                600
              ]
            },
            "description": "Filter to a single round duration (seconds)."
          }
        ],
        "responses": {
          "200": {
            "description": "Current state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WingoState"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          }
        }
      }
    },
    "/api/public/v1/wingo/bet": {
      "post": {
        "tags": [
          "Wingo"
        ],
        "summary": "Place a bet on the current open round",
        "description": "Atomically debits the main wallet and registers a bet on the open round for the given duration. The platform auto-settles when the round locks.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlaceBet"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Bet placed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BetReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient balance"
          },
          "409": {
            "description": "No open round"
          }
        }
      }
    },
    "/api/public/v1/k3/state": {
      "get": {
        "tags": [
          "K3"
        ],
        "summary": "Get live k3 round state",
        "description": "Returns all open rounds (one per duration) and recent settled history for k3.",
        "parameters": [
          {
            "name": "duration",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                30,
                60,
                180,
                300,
                600
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GameState"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Key not authorized for this game"
          }
        }
      }
    },
    "/api/public/v1/k3/bet": {
      "post": {
        "tags": [
          "K3"
        ],
        "summary": "Place a k3 bet on the open round",
        "description": "Atomically debits the main wallet and registers a bet. Selection rules vary per game — see GameBet schema.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GameBet"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Bet placed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BetReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient balance / subscription expired"
          },
          "409": {
            "description": "No open round"
          }
        }
      }
    },
    "/api/public/v1/5d/state": {
      "get": {
        "tags": [
          "5D"
        ],
        "summary": "Get live 5d round state",
        "description": "Returns all open rounds (one per duration) and recent settled history for 5d.",
        "parameters": [
          {
            "name": "duration",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                30,
                60,
                180,
                300,
                600
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GameState"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Key not authorized for this game"
          }
        }
      }
    },
    "/api/public/v1/5d/bet": {
      "post": {
        "tags": [
          "5D"
        ],
        "summary": "Place a 5d bet on the open round",
        "description": "Atomically debits the main wallet and registers a bet. Selection rules vary per game — see GameBet schema.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GameBet"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Bet placed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BetReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient balance / subscription expired"
          },
          "409": {
            "description": "No open round"
          }
        }
      }
    },
    "/api/public/v1/trx/state": {
      "get": {
        "tags": [
          "TRX"
        ],
        "summary": "Get live trx round state",
        "description": "Returns all open rounds (one per duration) and recent settled history for trx.",
        "parameters": [
          {
            "name": "duration",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                30,
                60,
                180,
                300,
                600
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GameState"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Key not authorized for this game"
          }
        }
      }
    },
    "/api/public/v1/trx/bet": {
      "post": {
        "tags": [
          "TRX"
        ],
        "summary": "Place a trx bet on the open round",
        "description": "Atomically debits the main wallet and registers a bet. Selection rules vary per game — see GameBet schema.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GameBet"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Bet placed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BetReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient balance / subscription expired"
          },
          "409": {
            "description": "No open round"
          }
        }
      }
    },
    "/api/public/v1/moto/state": {
      "get": {
        "tags": [
          "MOTO"
        ],
        "summary": "Get live moto round state",
        "description": "Returns all open rounds (one per duration) and recent settled history for moto.",
        "parameters": [
          {
            "name": "duration",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                30,
                60,
                180,
                300,
                600
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GameState"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Key not authorized for this game"
          }
        }
      }
    },
    "/api/public/v1/moto/bet": {
      "post": {
        "tags": [
          "MOTO"
        ],
        "summary": "Place a moto bet on the open round",
        "description": "Atomically debits the main wallet and registers a bet. Selection rules vary per game — see GameBet schema.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GameBet"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Bet placed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BetReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient balance / subscription expired"
          },
          "409": {
            "description": "No open round"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "publicKey:secret",
        "description": "Use `Authorization: Bearer <public_key>:<secret>` from a key created in the console."
      }
    },
    "schemas": {
      "WingoState": {
        "type": "object",
        "properties": {
          "api": {
            "type": "string",
            "example": "wingo"
          },
          "server_time": {
            "type": "string",
            "format": "date-time"
          },
          "rounds": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "round_no": {
                  "type": "integer"
                },
                "duration_seconds": {
                  "type": "integer",
                  "enum": [
                    30,
                    60,
                    180,
                    300,
                    600
                  ]
                },
                "opens_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "locks_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "seconds_remaining": {
                  "type": "integer"
                }
              }
            }
          },
          "history": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SettledRound"
            }
          }
        }
      },
      "SettledRound": {
        "type": "object",
        "properties": {
          "round_no": {
            "type": "integer"
          },
          "duration_seconds": {
            "type": "integer"
          },
          "result_number": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9
          },
          "result_color": {
            "type": "string",
            "enum": [
              "red",
              "green",
              "violet-red",
              "violet-green"
            ]
          },
          "result_size": {
            "type": "string",
            "enum": [
              "big",
              "small"
            ]
          },
          "settled_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PlaceBet": {
        "type": "object",
        "required": [
          "duration",
          "selection_type",
          "selection_value",
          "stake"
        ],
        "properties": {
          "duration": {
            "type": "integer",
            "enum": [
              30,
              60,
              180,
              300,
              600
            ]
          },
          "selection_type": {
            "type": "string",
            "enum": [
              "color",
              "number",
              "size"
            ]
          },
          "selection_value": {
            "type": "string",
            "example": "green",
            "description": "For color: red|green|violet. For number: 0-9. For size: big|small."
          },
          "stake": {
            "type": "number",
            "example": 10
          },
          "currency": {
            "type": "string",
            "example": "USD",
            "description": "Optional ISO-4217 code (USD, EUR, INR, PKR, BRL, NGN, AED, …). Recorded on the transaction ledger for display."
          },
          "idempotency_key": {
            "type": "string",
            "description": "Optional client-supplied dedupe key."
          }
        }
      },
      "BetReceipt": {
        "type": "object",
        "properties": {
          "bet_id": {
            "type": "string",
            "format": "uuid"
          },
          "round_no": {
            "type": "integer"
          },
          "duration_seconds": {
            "type": "integer"
          },
          "locks_at": {
            "type": "string",
            "format": "date-time"
          },
          "stake": {
            "type": "number"
          },
          "new_balance": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "won",
              "lost",
              "refunded"
            ]
          }
        }
      },
      "GameState": {
        "type": "object",
        "properties": {
          "api": {
            "type": "string",
            "example": "k3"
          },
          "server_time": {
            "type": "string",
            "format": "date-time"
          },
          "rounds": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "round_no": {
                  "type": "integer"
                },
                "duration_seconds": {
                  "type": "integer",
                  "enum": [
                    30,
                    60,
                    180,
                    300,
                    600
                  ]
                },
                "opens_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "locks_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "seconds_remaining": {
                  "type": "integer"
                }
              }
            }
          },
          "history": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "round_no": {
                  "type": "integer"
                },
                "duration_seconds": {
                  "type": "integer"
                },
                "result": {
                  "type": "object",
                  "description": "Game-specific result. K3:{dice,sum,size,parity}, 5D:{digits,sum,size}, TRX:{hash,number,color,size}, MOTO:{podium,winner}"
                },
                "settled_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "GameBet": {
        "type": "object",
        "required": [
          "duration",
          "selection_type",
          "selection_value",
          "stake"
        ],
        "description": "Selection rules — K3: type=size(big|small)|parity(odd|even)|sum(3-18). 5D: type=size(big|small). TRX: type=color(red|green|violet)|size(big|small)|number(0-9). MOTO: type=winner(Falcon|Blaze|Vortex|Phantom|Striker|Nova|Rogue|Apex).",
        "properties": {
          "duration": {
            "type": "integer",
            "enum": [
              30,
              60,
              180,
              300,
              600
            ]
          },
          "selection_type": {
            "type": "string",
            "example": "size"
          },
          "selection_value": {
            "type": "string",
            "example": "big"
          },
          "stake": {
            "type": "number",
            "example": 10
          },
          "currency": {
            "type": "string",
            "example": "USD",
            "description": "Optional ISO-4217 code for display/ledger labelling."
          },
          "idempotency_key": {
            "type": "string"
          }
        }
      }
    }
  }
}