{
  "openapi": "3.0.0",
  "info": {
    "title": "Ouro API",
    "version": "1.0.0",
    "description": "API for the Ouro platform"
  },
  "components": {
    "schemas": {
      "Asset": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "user_id": { "type": "string", "format": "uuid" },
          "org_id": { "type": "string", "format": "uuid" },
          "team_id": { "type": "string", "format": "uuid" },
          "asset_type": {
            "type": "string",
            "enum": [
              "user",
              "organization",
              "team",
              "dataset",
              "file",
              "service",
              "route",
              "post",
              "comment",
              "conversation"
            ]
          },
          "name": { "type": "string" },
          "name_url_slug": { "type": "string", "nullable": true },
          "slug": { "type": "string", "nullable": true },
          "description": {
            "oneOf": [
              { "type": "string" },
              {
                "type": "object",
                "properties": {
                  "text": { "type": "string" },
                  "json": { "type": "object" }
                },
                "required": ["text", "json"],
                "additionalProperties": true
              }
            ],
            "nullable": true
          },
          "visibility": {
            "type": "string",
            "enum": ["public", "private", "organization", "monetized"]
          },
          "monetization": {
            "type": "string",
            "enum": ["none", "pay-to-unlock", "pay-per-use"]
          },
          "price": { "type": "number", "nullable": true },
          "unit_cost": { "type": "number", "nullable": true },
          "cost_accounting": {
            "type": "string",
            "enum": ["fixed", "variable"],
            "nullable": true
          },
          "cost_unit": { "type": "string", "nullable": true },
          "product_id": { "type": "string", "nullable": true },
          "price_id": { "type": "string", "nullable": true },
          "metadata": { "type": "object", "nullable": true },
          "preview": {
            "type": "array",
            "items": { "type": "object" },
            "nullable": true
          },
          "created_at": { "type": "string", "format": "date-time" },
          "last_updated": { "type": "string", "format": "date-time" }
        }
      },
      "Dataset": {
        "allOf": [
          { "$ref": "#/components/schemas/Asset" },
          {
            "type": "object",
            "properties": {
              "asset_type": {
                "type": "string",
                "enum": ["dataset"]
              },
              "metadata": {
                "$ref": "#/components/schemas/DatasetMetadata"
              }
            }
          }
        ]
      },
      "DatasetMetadata": {
        "type": "object",
        "properties": {
          "table_name": { "type": "string" },
          "schema": { "type": "string", "enum": ["datasets"] },
          "columns": { "type": "array", "items": { "type": "string" } },
          "type": { "type": "string" },
          "size": { "type": "number" },
          "width": { "type": "number" },
          "height": { "type": "number" },
          "path": { "type": "string" },
          "fullPath": { "type": "string" },
          "name": { "type": "string" },
          "id": { "type": "string", "format": "uuid" }
        }
      },
      "CreateDataset": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "visibility": {
            "type": "string",
            "enum": ["public", "private", "organization", "monetized"],
            "nullable": true
          },
          "metadata": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "description": "Path to the file in Ouro's database"
              },
              "name": {
                "type": "string",
                "description": "File name with extension"
              }
            },
            "required": ["path", "name"]
          },
          "description": {
            "type": "string"
          },
          "org_id": {
            "type": "string",
            "format": "uuid"
          },
          "team_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": ["name", "metadata", "visibility"]
      },
      "UpdateDataset": {
        "type": "object",
        "properties": {
          "name": { "type": "string", "nullable": true },
          "description": { "type": "string", "nullable": true },
          "visibility": {
            "type": "string",
            "enum": ["public", "private", "organization", "monetized"],
            "nullable": true
          },
          "monetization": {
            "type": "string",
            "enum": ["pay-to-unlock", "pay-per-use"],
            "nullable": true,
            "description": "Pricing strategy. Visibility must monetized to set monetization"
          },
          "price": { "type": "number", "nullable": true },
          "team_id": { "type": "string", "format": "uuid", "nullable": true }
        },
        "required": []
      }
    }
  },
  "paths": {
    "/datasets/create/from-file": {
      "post": {
        "summary": "Create a dataset",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDataset"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dataset"
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Python",
            "source": "```python\ndata = pd.DataFrame(\n    [\n        {\"name\": \"Bob\", \"age\": 30},\n        {\"name\": \"Alice\", \"age\": 27},\n        {\"name\": \"Matt\", \"age\": 26},\n    ]\n)\n\nres = ouro.datasets.create(\n    data=data,\n    name=\"your_dataset_name\",\n    description=\"your_dataset_description\",\n    visibility=\"private\",\n)\n```"
          },
          {
            "lang": "JavaScript",
            "source": "```js```"
          }
        ]
      }
    },
    "/datasets/{id}": {
      "get": {
        "summary": "Read dataset",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dataset"
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Python",
            "source": "```python\nid = \"3d82308b-0747-45e4-8045-c8f7d2f6c0a6\" # penguins dataset\n\n# Retrieve a dataset\ndataset = ouro.datasets.retrieve(id)\n\n# Read dataset's data as a Pandas DataFrame\ndf = ouro.datasets.query(id)\n```"
          },
          {
            "lang": "JavaScript",
            "source": "```js```"
          }
        ]
      },
      "put": {
        "summary": "Update dataset",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateDataset"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dataset"
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Python",
            "source": "```python\nid = \"3d82308b-0747-45e4-8045-c8f7d2f6c0a6\"\ndata_update = pd.DataFrame([\n    {\"name\": \"Bob\", \"age\": 30},\n    {\"name\": \"Alice\", \"age\": 27},\n    {\"name\": \"Matt\", \"age\": 26},\n])\n\nupdate = {\n    \"visibility\": \"private\",\n    \"data\": data_update,\n}\ndata = ouro.datasets.update(\"018f86da-b1be-7099-9556-fe88fb6882c3\", **update)\n```"
          },
          {
            "lang": "JavaScript",
            "source": "```js```"
          }
        ]
      },
      "delete": {
        "summary": "Delete dataset",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response"
          }
        }
      }
    },
    "/datasets/{id}/data": {
      "get": {
        "summary": "Read dataset data",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/datasets/{id}/schema": {
      "get": {
        "summary": "Read dataset schema",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/datasets/{id}/stats": {
      "get": {
        "summary": "Read dataset stats",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/datasets/{id}/permissions": {
      "get": {
        "summary": "Read dataset permissions",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  }
}
