{
  "openapi": "3.1.0",
  "info": {
    "title": "Tashkeel Public API",
    "version": "0.1.0",
    "description": "Read-only public surface of the Tashkeel 3D printing platform, served by Supabase PostgREST. Authenticated endpoints exist but are restricted by Row-Level Security and are not documented here.",
    "contact": {
      "name": "Tashkeel Support",
      "email": "support@tashkeel.pro",
      "url": "https://tashkeel.pro/about"
    },
    "license": { "name": "Proprietary" }
  },
  "servers": [
    { "url": "https://cfvunxcoomhbgkodpxhe.supabase.co/rest/v1", "description": "Production" }
  ],
  "components": {
    "securitySchemes": {
      "anonKey": {
        "type": "apiKey",
        "in": "header",
        "name": "apikey",
        "description": "Public anon key (embedded in the SPA bundle). Required on every request."
      },
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "Material": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "name_ar": { "type": "string" },
          "density": { "type": "number" },
          "price_per_gram": { "type": "number" },
          "colors": { "type": "array", "items": { "type": "string" } },
          "is_active": { "type": "boolean" }
        }
      },
      "PricingSetting": {
        "type": "object",
        "properties": {
          "key": { "type": "string" },
          "value": { "type": "string" },
          "description": { "type": "string", "nullable": true }
        }
      },
      "MarketplaceProduct": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "title_ar": { "type": "string", "nullable": true },
          "description": { "type": "string", "nullable": true },
          "price": { "type": "number" },
          "product_type": { "type": "string", "enum": ["physical", "digital"] },
          "stock_quantity": { "type": "integer", "nullable": true },
          "category": { "type": "string", "nullable": true },
          "is_active": { "type": "boolean" },
          "is_approved": { "type": "boolean" }
        }
      },
      "QuoteRequest": {
        "type": "object",
        "required": ["p_volume_cm3", "p_surface_area_mm2", "p_model_height_mm", "p_infill_percentage", "p_wall_strength", "p_quality", "p_finish", "p_supports", "p_material_id"],
        "properties": {
          "p_volume_cm3": { "type": "number" },
          "p_surface_area_mm2": { "type": "number" },
          "p_model_height_mm": { "type": "number" },
          "p_infill_percentage": { "type": "integer", "minimum": 5, "maximum": 100 },
          "p_wall_strength": { "type": "string", "enum": ["standard", "strong"] },
          "p_quality": { "type": "string", "enum": ["low", "standard", "high", "super"] },
          "p_finish": { "type": "string", "enum": ["standard", "sanded", "painted", "polished"] },
          "p_supports": { "type": "boolean" },
          "p_material_id": { "type": "string", "format": "uuid" }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "properties": {
          "material_cost": { "type": "number" },
          "printing_cost": { "type": "number" },
          "finish_cost": { "type": "number" },
          "support_cost": { "type": "number" },
          "item_total": { "type": "number", "description": "EGP, rounded" },
          "weight_grams": { "type": "number" },
          "print_time_hours": { "type": "number" }
        }
      }
    }
  },
  "security": [{ "anonKey": [] }],
  "paths": {
    "/materials": {
      "get": {
        "summary": "List active 3D printing materials",
        "parameters": [
          { "name": "is_active", "in": "query", "schema": { "type": "string" }, "example": "eq.true" },
          { "name": "select", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Material catalog",
            "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Material" } } } }
          }
        }
      }
    },
    "/pricing_settings": {
      "get": {
        "summary": "Public pricing tunables (printing cost/hour, finish tiers, layer heights, etc.)",
        "responses": {
          "200": {
            "description": "Settings array",
            "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/PricingSetting" } } } }
          }
        }
      }
    },
    "/marketplace_products": {
      "get": {
        "summary": "List approved active marketplace products",
        "parameters": [
          { "name": "is_active", "in": "query", "schema": { "type": "string" }, "example": "eq.true" },
          { "name": "is_approved", "in": "query", "schema": { "type": "string" }, "example": "eq.true" }
        ],
        "responses": {
          "200": {
            "description": "Public catalog",
            "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/MarketplaceProduct" } } } }
          }
        }
      }
    },
    "/rpc/calculate_item_price": {
      "post": {
        "summary": "Compute an instant 3D print quote",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QuoteRequest" } } }
        },
        "responses": {
          "200": {
            "description": "Cost breakdown",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QuoteResponse" } } }
          }
        }
      }
    }
  }
}
