{
  "openapi": "3.1.0",
  "info": {
    "title": "Tulqui Public Read API",
    "version": "1.0.0",
    "description": "Public business catalog and availability. No booking writes, cancellation or charges. Customers confirm through booking_url. test_mode marks fictional/test businesses."
  },
  "servers": [
    {
      "url": "https://tulqui.com"
    }
  ],
  "paths": {
    "/api/v1/businesses/{slug}": {
      "get": {
        "operationId": "getBusinessCatalog",
        "description": "Read a published, active business catalog. Prices are GTQ cents.",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]{2,39}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful public read",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "schema_version": {
                      "type": "string"
                    },
                    "timezone": {
                      "type": "string",
                      "const": "America/Guatemala"
                    },
                    "currency": {
                      "type": "string",
                      "const": "GTQ"
                    },
                    "test_mode": {
                      "type": "boolean"
                    },
                    "booking_url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "business": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "slug": {
                          "type": "string"
                        },
                        "description": {
                          "type": "string"
                        },
                        "address": {
                          "type": "string"
                        },
                        "phone": {
                          "type": "string"
                        }
                      }
                    },
                    "config_version": {
                      "type": "integer"
                    },
                    "services": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Service"
                      }
                    },
                    "staff": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          },
                          "service_ids": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "format": "uuid"
                            }
                          }
                        }
                      }
                    },
                    "cancellation_policy": {
                      "type": "string"
                    },
                    "availability_url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "capabilities": {
                      "type": "object"
                    },
                    "next_action": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found or unavailable business",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service temporarily unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/businesses/{slug}/availability": {
      "get": {
        "operationId": "getBusinessAvailability",
        "description": "Read current availability. Does not hold or reserve slots. Up to 60 days ahead in Guatemala local time.",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]{2,39}$"
            }
          },
          {
            "name": "service",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "staff",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful public read",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "schema_version": {
                      "type": "string"
                    },
                    "timezone": {
                      "type": "string",
                      "const": "America/Guatemala"
                    },
                    "currency": {
                      "type": "string",
                      "const": "GTQ"
                    },
                    "test_mode": {
                      "type": "boolean"
                    },
                    "booking_url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "date": {
                      "type": "string",
                      "format": "date"
                    },
                    "service_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "staff_id": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "slots": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "format": "date-time"
                      }
                    },
                    "checked_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "refresh_after_seconds": {
                      "type": "integer",
                      "const": 30
                    },
                    "reserved": {
                      "type": "boolean",
                      "const": false
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found or unavailable business",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service temporarily unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Service": {
        "type": "object",
        "required": [
          "id",
          "name",
          "duration_minutes",
          "price_cents",
          "upfront_cents",
          "balance_cents",
          "payment_mode"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "duration_minutes": {
            "type": "integer",
            "minimum": 1
          },
          "price_cents": {
            "type": "integer",
            "minimum": 0
          },
          "upfront_cents": {
            "type": "integer",
            "minimum": 0
          },
          "balance_cents": {
            "type": "integer",
            "minimum": 0
          },
          "payment_mode": {
            "type": "string",
            "enum": [
              "at_appointment",
              "deposit",
              "full"
            ]
          }
        }
      }
    }
  }
}
