{
  "openapi": "3.1.0",
  "info": {
    "title": "OGQ Partner API",
    "version": "1.0.0",
    "description": "OGQ IP Marketplace Partner API — Search, purchase, download, and embed global IP assets.",
    "contact": { "email": "dev@ogq.me" },
    "license": { "name": "Proprietary", "url": "https://ogq.itshin.com/terms" }
  },
  "servers": [
    { "url": "https://ogq.itshin.com/api/v1", "description": "Production" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer" }
    },
    "schemas": {
      "IpItem": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": "string" },
          "type": { "type": "string" },
          "originType": { "type": "string", "enum": ["human", "ai", "hybrid"] },
          "price": { "type": "number" },
          "currency": { "type": "string" },
          "creatorId": { "type": "string" },
          "creatorName": { "type": "string" },
          "thumbnailUrl": { "type": "string", "format": "uri" },
          "purchaseCount": { "type": "integer" },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  },
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "security": [],
        "responses": { "200": { "description": "OK" } }
      }
    },
    "/ip/search": {
      "get": {
        "summary": "Search IP catalog",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string" } },
          { "name": "type", "in": "query", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20, "maximum": 100 } },
          { "name": "cursor", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": { "type": "array", "items": { "$ref": "#/components/schemas/IpItem" } },
                    "nextCursor": { "type": "string", "nullable": true },
                    "count": { "type": "integer" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/ip/{id}": {
      "get": {
        "summary": "Get IP detail (DCAT-AP JSON-LD)",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "IP detail with DCAT-AP context" },
          "404": { "description": "Not found" }
        }
      }
    },
    "/ip/{id}/purchase": {
      "post": {
        "summary": "Purchase an IP",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "Idempotency-Key", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "201": { "description": "Purchase initiated" },
          "400": { "description": "Missing Idempotency-Key" },
          "402": { "description": "Insufficient credits" }
        }
      }
    },
    "/ip/{id}/download": {
      "get": {
        "summary": "Get signed download URL",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Signed URL with 15-min expiry" } }
      }
    },
    "/ip/{id}/embed": {
      "post": {
        "summary": "Generate embed URL and iframe snippet",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "width": { "type": "integer", "default": 400 },
                  "height": { "type": "integer", "default": 300 },
                  "theme": { "type": "string", "enum": ["light", "dark"], "default": "light" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Embed URL" } }
      }
    },
    "/webhook/register": {
      "post": {
        "summary": "Register a webhook endpoint",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url", "events"],
                "properties": {
                  "url": { "type": "string", "format": "uri" },
                  "events": {
                    "type": "array",
                    "items": { "type": "string", "enum": ["ip.created", "ip.updated", "ip.purchased", "settlement.completed"] }
                  },
                  "secret": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Webhook registered" } }
      }
    }
  }
}
