{
 "openapi": "3.1.0",
 "info": {
  "title": "API de Shulada",
  "version": "1.0.0",
  "description": "Endpoints para integrar un sistema externo con una tienda de Shulada: catálogo, inventario, precios, pedidos y eventos. Guía completa en https://shulada.com/docs"
 },
 "servers": [
  {
   "url": "https://shulada.com"
  }
 ],
 "security": [
  {
   "bearer": []
  }
 ],
 "tags": [
  {
   "name": "Autenticación"
  },
  {
   "name": "Catálogo"
  },
  {
   "name": "Productos"
  },
  {
   "name": "Inventario"
  },
  {
   "name": "Precios"
  },
  {
   "name": "Cargas masivas"
  },
  {
   "name": "Pedidos"
  },
  {
   "name": "Eventos"
  }
 ],
 "paths": {
  "/v1/apps/me": {
   "get": {
    "tags": [
     "Autenticación"
    ],
    "summary": "Identidad y permisos del token",
    "description": "Permiso mínimo: `cualquier token de gestión`.",
    "responses": {
     "200": {
      "description": "Token válido",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    }
   }
  },
  "/v1/catalog/categories": {
   "get": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Listar categorías",
    "description": "Permiso mínimo: `catalog: read`.",
    "responses": {
     "200": {
      "description": "Categorías",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Category"
           }
          },
          "nextCursor": {
           "type": "string"
          },
          "total": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Crear categoría",
    "description": "Permiso mínimo: `catalog: edit`.",
    "responses": {
     "201": {
      "description": "Creada",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Category"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name"
        ],
        "properties": {
         "name": {
          "type": "string"
         },
         "parentId": {
          "type": "string"
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/catalog/categories/{id}": {
   "put": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Editar categoría",
    "description": "Permiso mínimo: `catalog: edit`.",
    "responses": {
     "200": {
      "description": "Guardada",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Category"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Borrar categoría",
    "description": "Permiso mínimo: `catalog: edit`.",
    "responses": {
     "204": {
      "description": "Borrada"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/catalog/brands": {
   "get": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Listar marcas",
    "description": "Permiso mínimo: `catalog: read`.",
    "responses": {
     "200": {
      "description": "Marcas",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Brand"
           }
          },
          "nextCursor": {
           "type": "string"
          },
          "total": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Crear marca",
    "description": "Permiso mínimo: `catalog: edit`.",
    "responses": {
     "201": {
      "description": "Creada",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Brand"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name"
        ],
        "properties": {
         "name": {
          "type": "string"
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/catalog/media": {
   "post": {
    "tags": [
     "Catálogo"
    ],
    "summary": "Subir imagen",
    "description": "Permiso mínimo: `catalog: edit`.",
    "responses": {
     "200": {
      "description": "Ya existía (mismo archivo)",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "media": {
           "$ref": "#/components/schemas/Media"
          },
          "duplicate": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "201": {
      "description": "Creada",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "media": {
           "$ref": "#/components/schemas/Media"
          },
          "duplicate": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "required": [
         "file",
         "alt"
        ],
        "properties": {
         "file": {
          "type": "string",
          "format": "binary",
          "description": "Hasta 10 MB."
         },
         "alt": {
          "type": "string",
          "description": "Texto alternativo."
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/products": {
   "get": {
    "tags": [
     "Productos"
    ],
    "summary": "Listar productos",
    "description": "Permiso mínimo: `catalog: read`.",
    "responses": {
     "200": {
      "description": "Productos",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Product"
           }
          },
          "nextCursor": {
           "type": "string"
          },
          "total": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "description": "1 a 250 (50 por defecto).",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "description": "nextCursor de la página anterior.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "q",
      "in": "query",
      "description": "Búsqueda por texto o SKU.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "status",
      "in": "query",
      "description": "active, draft o archived.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "stock",
      "in": "query",
      "description": "in, out o low.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "category",
      "in": "query",
      "description": "Id de categoría.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "brand",
      "in": "query",
      "description": "Marca.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "type",
      "in": "query",
      "description": "Tipo.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "tag",
      "in": "query",
      "description": "Etiqueta.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "sort",
      "in": "query",
      "description": "title, updated, created, stock, price o status; con - para descendente.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "fields",
      "in": "query",
      "description": "Campos a devolver, separados por coma.",
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "post": {
    "tags": [
     "Productos"
    ],
    "summary": "Crear producto con id generado",
    "description": "Permiso mínimo: `catalog: edit`.",
    "responses": {
     "201": {
      "description": "Creado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SavedProduct"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ProductInput"
       }
      }
     }
    }
   }
  },
  "/v1/products/{id}": {
   "get": {
    "tags": [
     "Productos"
    ],
    "summary": "Leer producto",
    "description": "Permiso mínimo: `catalog: read`.",
    "responses": {
     "200": {
      "description": "Producto",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Product"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "put": {
    "tags": [
     "Productos"
    ],
    "summary": "Crear o reemplazar producto con id propio",
    "description": "Reemplaza el producto completo. Repetir la llamada es seguro.\n\nPermiso mínimo: `catalog: edit`.",
    "responses": {
     "200": {
      "description": "Guardado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SavedProduct"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-Match",
      "in": "header",
      "description": "Versión esperada, entre comillas. Si no coincide: 412.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ProductInput"
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Productos"
    ],
    "summary": "Borrar producto",
    "description": "Permiso mínimo: `catalog: admin`.",
    "responses": {
     "204": {
      "description": "Borrado"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/inventory/{sku}": {
   "get": {
    "tags": [
     "Inventario"
    ],
    "summary": "Existencias de un SKU",
    "description": "Permiso mínimo: `inventory: read`.",
    "responses": {
     "200": {
      "description": "Existencias",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Inventory"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "sku",
      "in": "path",
      "required": true,
      "description": "SKU.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/inventory/{sku}/{location}": {
   "put": {
    "tags": [
     "Inventario"
    ],
    "summary": "Fijar existencias de un SKU en una ubicación",
    "description": "Permiso mínimo: `inventory: edit`.",
    "responses": {
     "204": {
      "description": "Guardado"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "sku",
      "in": "path",
      "required": true,
      "description": "SKU.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "location",
      "in": "path",
      "required": true,
      "description": "Id de ubicación, por ejemplo principal.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "onHand"
        ],
        "properties": {
         "onHand": {
          "type": "integer",
          "minimum": 0
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/locations": {
   "get": {
    "tags": [
     "Inventario"
    ],
    "summary": "Listar ubicaciones",
    "description": "Permiso mínimo: `settings: read`.",
    "responses": {
     "200": {
      "description": "Ubicaciones",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    }
   }
  },
  "/v1/prices/{channel}/{sku}": {
   "get": {
    "tags": [
     "Precios"
    ],
    "summary": "Leer precios de un SKU",
    "description": "Permiso mínimo: `pricing: read`.",
    "responses": {
     "200": {
      "description": "Precios",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PriceTiers"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "channel",
      "in": "path",
      "required": true,
      "description": "Canal de venta, por ejemplo mx.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "sku",
      "in": "path",
      "required": true,
      "description": "SKU.",
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "put": {
    "tags": [
     "Precios"
    ],
    "summary": "Fijar precios de un SKU",
    "description": "Permiso mínimo: `pricing: edit`.",
    "responses": {
     "204": {
      "description": "Guardado"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "channel",
      "in": "path",
      "required": true,
      "description": "Canal de venta, por ejemplo mx.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "sku",
      "in": "path",
      "required": true,
      "description": "SKU.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PriceTiers"
       }
      }
     }
    }
   }
  },
  "/v1/bulk-operations": {
   "post": {
    "tags": [
     "Cargas masivas"
    ],
    "summary": "Crear operación masiva de existencias o precios",
    "description": "Permiso mínimo: `inventory: edit (y pricing: edit para precios)`.",
    "responses": {
     "202": {
      "description": "Aceptada",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BulkJob"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BulkRequest"
       }
      }
     }
    }
   }
  },
  "/v1/bulk-operations/{id}": {
   "get": {
    "tags": [
     "Cargas masivas"
    ],
    "summary": "Consultar operación masiva",
    "description": "Permiso mínimo: `inventory: read`.",
    "responses": {
     "200": {
      "description": "Operación",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BulkJob"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/orders": {
   "get": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Listar pedidos",
    "description": "Permiso mínimo: `orders: read`.",
    "responses": {
     "200": {
      "description": "Pedidos",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Order"
           }
          },
          "nextCursor": {
           "type": "string"
          },
          "total": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "description": "pending_payment, paid, fulfilled, cancelled, refunded (varios con coma).",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "payment",
      "in": "query",
      "description": "pending, paid, balance_due, partially_refunded, refunded, voided.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "fulfillment",
      "in": "query",
      "description": "unfulfilled, partial, fulfilled, delivered.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "from",
      "in": "query",
      "description": "Creado desde: AAAA-MM-DD o RFC 3339.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "to",
      "in": "query",
      "description": "Creado hasta.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "q",
      "in": "query",
      "description": "Búsqueda.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "channel",
      "in": "query",
      "description": "Canal de venta.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "customer",
      "in": "query",
      "description": "Id de cliente.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "sort",
      "in": "query",
      "description": "number_desc, number_asc, total_desc o total_asc.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "description": "Tamaño de página.",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "description": "nextCursor de la página anterior.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/orders/{id}": {
   "get": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Leer pedido",
    "description": "Permiso mínimo: `orders: read`.",
    "responses": {
     "200": {
      "description": "Pedido",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/orders/{id}/fulfillments": {
   "post": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Registrar envío",
    "description": "Permiso mínimo: `orders: edit`.",
    "responses": {
     "201": {
      "description": "Pedido actualizado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/FulfillmentInput"
       }
      }
     }
    }
   }
  },
  "/v1/orders/{id}/fulfillments/{fulfillment}": {
   "patch": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Editar envío o cambiar su estado",
    "description": "Permiso mínimo: `orders: edit`.",
    "responses": {
     "200": {
      "description": "Pedido actualizado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "fulfillment",
      "in": "path",
      "required": true,
      "description": "Id del envío.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "action": {
          "type": "string",
          "enum": [
           "ship",
           "deliver",
           "cancel"
          ]
         },
         "carrier": {
          "type": "string"
         },
         "trackingNumber": {
          "type": "string"
         },
         "trackingUrl": {
          "type": "string"
         },
         "notify": {
          "type": "boolean"
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/orders/{id}/fulfill": {
   "post": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Marcar todo el pedido como surtido",
    "description": "Permiso mínimo: `orders: edit`.",
    "responses": {
     "200": {
      "description": "Pedido actualizado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/orders/{id}/cancel": {
   "post": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Cancelar pedido",
    "description": "Si ya estaba pagado, también lo reembolsa.\n\nPermiso mínimo: `orders: edit`.",
    "responses": {
     "200": {
      "description": "Pedido actualizado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "reason": {
          "type": "string"
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/orders/{id}/refunds": {
   "post": {
    "tags": [
     "Pedidos"
    ],
    "summary": "Reembolsar",
    "description": "Permiso mínimo: `orders: edit`.",
    "responses": {
     "201": {
      "description": "Pedido actualizado",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RefundInput"
       }
      }
     }
    }
   }
  },
  "/v1/webhooks": {
   "get": {
    "tags": [
     "Eventos"
    ],
    "summary": "Listar webhooks",
    "description": "Permiso mínimo: `settings: read`.",
    "responses": {
     "200": {
      "description": "Suscripciones",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Webhook"
           }
          },
          "nextCursor": {
           "type": "string"
          },
          "total": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Eventos"
    ],
    "summary": "Crear webhook",
    "description": "Permiso mínimo: `settings: admin`.",
    "responses": {
     "201": {
      "description": "Creado",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "subscription": {
           "$ref": "#/components/schemas/Webhook"
          },
          "secret": {
           "type": "string",
           "description": "Se muestra una sola vez."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/WebhookInput"
       }
      }
     }
    }
   }
  },
  "/v1/webhooks/{id}": {
   "delete": {
    "tags": [
     "Eventos"
    ],
    "summary": "Desactivar webhook",
    "description": "Permiso mínimo: `settings: admin`.",
    "responses": {
     "204": {
      "description": "Desactivado"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/webhooks/{id}/deliveries": {
   "get": {
    "tags": [
     "Eventos"
    ],
    "summary": "Últimas entregas de un webhook",
    "description": "Permiso mínimo: `settings: read`.",
    "responses": {
     "200": {
      "description": "Entregas",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/v1/webhooks/{id}/replay": {
   "post": {
    "tags": [
     "Eventos"
    ],
    "summary": "Reenviar eventos posteriores a una secuencia",
    "description": "Permiso mínimo: `settings: admin`.",
    "responses": {
     "200": {
      "description": "Reencolados",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "requeued": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Identificador.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "after",
      "in": "query",
      "description": "Secuencia a partir de la cual reenviar.",
      "schema": {
       "type": "integer"
      }
     }
    ]
   }
  },
  "/v1/events": {
   "get": {
    "tags": [
     "Eventos"
    ],
    "summary": "Feed de eventos",
    "description": "Permiso mínimo: `settings: read`.",
    "responses": {
     "200": {
      "description": "Eventos",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Event"
           }
          },
          "next": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/problem+json": {
        "schema": {
         "$ref": "#/components/schemas/Problem"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "after",
      "in": "query",
      "description": "Secuencia del último evento ya leído.",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "description": "Hasta 500 (100 por defecto).",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "types",
      "in": "query",
      "description": "Tipos separados por coma.",
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer",
    "description": "Token de App (apa_…) o llave de API (apx_…) de la tienda."
   }
  },
  "schemas": {
   "Problem": {
    "type": "object",
    "properties": {
     "title": {
      "type": "string"
     },
     "status": {
      "type": "integer"
     },
     "code": {
      "type": "string",
      "description": "Código estable para programas."
     },
     "detail": {
      "type": "string"
     },
     "errors": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "field": {
         "type": "string"
        },
        "code": {
         "type": "string"
        },
        "message": {
         "type": "string"
        }
       }
      }
     }
    }
   },
   "Money": {
    "type": "object",
    "required": [
     "amount",
     "currency"
    ],
    "properties": {
     "amount": {
      "type": "integer",
      "description": "Monto con dos decimales implícitos en toda moneda: 129900 = $1,299.00 MXN; 50000000 = Rp 500.000."
     },
     "currency": {
      "type": "string",
      "example": "MXN"
     }
    }
   },
   "Variant": {
    "type": "object",
    "required": [
     "sku"
    ],
    "properties": {
     "sku": {
      "type": "string",
      "maxLength": 80
     },
     "title": {
      "type": "string"
     },
     "options": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      }
     },
     "barcode": {
      "type": "string"
     },
     "weightGrams": {
      "type": "integer"
     },
     "mediaId": {
      "type": "string",
      "description": "Foto principal de la variante."
     },
     "mediaIds": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "maxItems": 100,
      "description": "Todas las fotos de la variante, en orden; la primera es la principal."
     },
     "lengthMm": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100000
     },
     "widthMm": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100000
     },
     "heightMm": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100000
     }
    }
   },
   "ProductInput": {
    "type": "object",
    "required": [
     "handle",
     "title",
     "variants"
    ],
    "properties": {
     "handle": {
      "type": "string",
      "description": "Dirección del producto: minúsculas, números y guiones."
     },
     "title": {
      "type": "string",
      "maxLength": 200
     },
     "description": {
      "type": "string",
      "maxLength": 20000
     },
     "brand": {
      "type": "string"
     },
     "brandId": {
      "type": "string"
     },
     "categories": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "maxItems": 20
     },
     "status": {
      "type": "string",
      "enum": [
       "active",
       "draft",
       "archived"
      ],
      "default": "active"
     },
     "type": {
      "type": "string"
     },
     "tags": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "attributes": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      }
     },
     "options": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "values": {
         "type": "array",
         "items": {
          "type": "string"
         }
        }
       }
      }
     },
     "variants": {
      "type": "array",
      "minItems": 1,
      "items": {
       "$ref": "#/components/schemas/Variant"
      }
     },
     "media": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "maxItems": 1000,
      "description": "Ids de imagen; la primera es la portada."
     },
     "seoTitle": {
      "type": "string"
     },
     "seoDescription": {
      "type": "string"
     },
     "prices": {
      "type": "object",
      "description": "Por SKU. Requiere pricing: edit.",
      "additionalProperties": {
       "type": "object",
       "required": [
        "amount"
       ],
       "properties": {
        "amount": {
         "type": "integer"
        },
        "compareAt": {
         "type": [
          "integer",
          "null"
         ]
        },
        "currency": {
         "type": "string"
        }
       }
      }
     },
     "stock": {
      "type": "object",
      "description": "Por SKU y ubicación. Requiere inventory: edit.",
      "additionalProperties": {
       "type": "object",
       "additionalProperties": {
        "type": "integer"
       }
      }
     }
    }
   },
   "Product": {
    "allOf": [
     {
      "$ref": "#/components/schemas/ProductInput"
     },
     {
      "type": "object",
      "properties": {
       "id": {
        "type": "string"
       },
       "version": {
        "type": "integer"
       },
       "createdAt": {
        "type": "string",
        "format": "date-time"
       },
       "updatedAt": {
        "type": "string",
        "format": "date-time"
       },
       "available": {
        "type": "object",
        "additionalProperties": {
         "type": "integer"
        }
       },
       "levels": {
        "type": "object",
        "additionalProperties": {
         "type": "array",
         "items": {
          "$ref": "#/components/schemas/StockLevel"
         }
        }
       },
       "pricing": {
        "type": "object",
        "additionalProperties": {
         "type": "object"
        }
       }
      }
     }
    ]
   },
   "SavedProduct": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "version": {
      "type": "integer"
     }
    }
   },
   "StockLevel": {
    "type": "object",
    "properties": {
     "locationId": {
      "type": "string"
     },
     "onHand": {
      "type": "integer"
     },
     "reserved": {
      "type": "integer"
     }
    }
   },
   "Inventory": {
    "type": "object",
    "properties": {
     "sku": {
      "type": "string"
     },
     "available": {
      "type": "integer"
     },
     "levels": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/StockLevel"
      }
     },
     "updatedAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "PriceTiers": {
    "type": "object",
    "required": [
     "tiers"
    ],
    "properties": {
     "tiers": {
      "type": "array",
      "minItems": 1,
      "items": {
       "type": "object",
       "required": [
        "minQty",
        "unit"
       ],
       "properties": {
        "minQty": {
         "type": "integer",
         "minimum": 1
        },
        "unit": {
         "$ref": "#/components/schemas/Money"
        },
        "compareAt": {
         "$ref": "#/components/schemas/Money"
        }
       }
      }
     }
    }
   },
   "BulkRequest": {
    "type": "object",
    "required": [
     "kind",
     "items"
    ],
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "stock",
       "prices"
      ]
     },
     "channel": {
      "type": "string",
      "description": "Obligatorio para prices."
     },
     "items": {
      "type": "array",
      "maxItems": 20000,
      "items": {
       "type": "object",
       "description": "stock: {sku, location, onHand}. prices: {sku, amount, compareAt}."
      }
     }
    }
   },
   "BulkJob": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "kind": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "queued",
       "running",
       "done"
      ]
     },
     "total": {
      "type": "integer"
     },
     "processed": {
      "type": "integer"
     },
     "failed": {
      "type": "integer"
     },
     "errors": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "line": {
         "type": "integer"
        },
        "sku": {
         "type": "string"
        },
        "message": {
         "type": "string"
        }
       }
      }
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     },
     "finishedAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "OrderLine": {
    "type": "object",
    "properties": {
     "line": {
      "type": "integer"
     },
     "sku": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "qty": {
      "type": "integer"
     },
     "unit": {
      "type": "integer"
     },
     "total": {
      "type": "integer"
     },
     "fulfilledQty": {
      "type": "integer"
     },
     "returnedQty": {
      "type": "integer"
     },
     "refundedQty": {
      "type": "integer"
     },
     "cancelledQty": {
      "type": "integer"
     }
    }
   },
   "Fulfillment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "number": {
      "type": "integer"
     },
     "status": {
      "type": "string"
     },
     "carrier": {
      "type": "string"
     },
     "trackingNumber": {
      "type": "string"
     },
     "trackingUrl": {
      "type": "string"
     },
     "items": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     },
     "shippedAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Order": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "number": {
      "type": "integer"
     },
     "channel": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "pending_payment",
       "paid",
       "fulfilled",
       "cancelled",
       "refunded"
      ]
     },
     "paymentStatus": {
      "type": "string",
      "enum": [
       "pending",
       "paid",
       "balance_due",
       "partially_refunded",
       "refunded",
       "voided"
      ]
     },
     "fulfillmentStatus": {
      "type": "string",
      "enum": [
       "unfulfilled",
       "partial",
       "fulfilled",
       "delivered"
      ]
     },
     "currency": {
      "type": "string"
     },
     "itemsTotal": {
      "type": "integer"
     },
     "discounts": {
      "type": "integer"
     },
     "shipping": {
      "type": "integer"
     },
     "taxIncluded": {
      "type": "integer"
     },
     "grandTotal": {
      "type": "integer"
     },
     "paidTotal": {
      "type": "integer"
     },
     "refundedTotal": {
      "type": "integer"
     },
     "balance": {
      "type": "integer"
     },
     "customerId": {
      "type": "string"
     },
     "customer": {
      "type": "object",
      "properties": {
       "email": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "phone": {
        "type": "string"
       },
       "address": {
        "type": "string"
       },
       "notes": {
        "type": "string"
       }
      }
     },
     "postalCode": {
      "type": "string"
     },
     "shippingMethod": {
      "type": "object"
     },
     "lines": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "$ref": "#/components/schemas/OrderLine"
      },
      "description": "Solo en el detalle."
     },
     "payments": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "fulfillments": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Fulfillment"
      }
     },
     "source": {
      "type": "string"
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "FulfillmentInput": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "description": "Vacío = todo lo pendiente.",
      "items": {
       "type": "object",
       "properties": {
        "line": {
         "type": "integer"
        },
        "qty": {
         "type": "integer"
        }
       }
      }
     },
     "carrier": {
      "type": "string"
     },
     "trackingNumber": {
      "type": "string"
     },
     "trackingUrl": {
      "type": "string"
     },
     "note": {
      "type": "string"
     },
     "pending": {
      "type": "boolean",
      "description": "Preparar ahora y marcar enviado después."
     },
     "notify": {
      "type": "boolean",
      "description": "Avisar al cliente por correo."
     }
    }
   },
   "RefundInput": {
    "type": "object",
    "properties": {
     "lines": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "line": {
         "type": "integer"
        },
        "qty": {
         "type": "integer"
        }
       }
      }
     },
     "shipping": {
      "type": "integer"
     },
     "amount": {
      "type": "integer"
     },
     "reason": {
      "type": "string"
     },
     "restock": {
      "type": "boolean"
     },
     "notify": {
      "type": "boolean"
     }
    }
   },
   "WebhookInput": {
    "type": "object",
    "required": [
     "url"
    ],
    "properties": {
     "url": {
      "type": "string",
      "format": "uri",
      "description": "https y pública."
     },
     "types": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Vacío = todos los eventos."
     }
    }
   },
   "Webhook": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "url": {
      "type": "string"
     },
     "types": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "active": {
      "type": "boolean"
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Event": {
    "type": "object",
    "description": "CloudEvent 1.0.",
    "properties": {
     "specversion": {
      "type": "string"
     },
     "id": {
      "type": "string"
     },
     "source": {
      "type": "string"
     },
     "type": {
      "type": "string",
      "example": "apexx.order.paid"
     },
     "subject": {
      "type": "string"
     },
     "time": {
      "type": "string",
      "format": "date-time"
     },
     "apexxtenant": {
      "type": "string"
     },
     "apexxsequence": {
      "type": "integer"
     },
     "datacontenttype": {
      "type": "string"
     },
     "data": {}
    }
   },
   "Category": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "parentId": {
      "type": "string"
     },
     "handle": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "active": {
      "type": "boolean"
     },
     "position": {
      "type": "integer"
     }
    }
   },
   "Brand": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "handle": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "active": {
      "type": "boolean"
     }
    }
   },
   "Media": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "filename": {
      "type": "string"
     },
     "contentType": {
      "type": "string"
     },
     "width": {
      "type": "integer"
     },
     "height": {
      "type": "integer"
     },
     "alt": {
      "type": "string"
     },
     "url": {
      "type": "string"
     },
     "thumb": {
      "type": "string"
     }
    }
   }
  }
 }
}