{
  "openapi": "3.0.3",
  "info": {
    "title": "pedidofacil — Admin API",
    "version": "1.0.0",
    "description": "API compatível com a Admin API de apps de mercado (token OAuth2 password, recursos de pedidos e status, webhooks) com extensão para o módulo Meu Evento. Troque apenas a URL base e as credenciais no seu ERP."
  },
  "servers": [
    {
      "url": "https://meudelivery.store/api/public/admin-api"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "responses": {
      "Error": {
        "description": "Erro",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "OrderItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "productId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "unitPrice": {
            "type": "number"
          },
          "total": {
            "type": "number"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "WARNING",
              "WAITING",
              "APPROVED",
              "IN_TRANSIT",
              "DONE",
              "REJECTED",
              "HIDDEN"
            ]
          },
          "type": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "customer": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              }
            }
          },
          "address": {
            "type": "object",
            "properties": {
              "formatted": {
                "type": "string"
              },
              "complement": {
                "type": "string"
              },
              "lat": {
                "type": "number"
              },
              "lng": {
                "type": "number"
              }
            }
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderItem"
            }
          },
          "payment": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "method": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "changeFor": {
                "type": "number"
              }
            }
          },
          "subtotal": {
            "type": "number"
          },
          "deliveryFee": {
            "type": "number"
          },
          "discount": {
            "type": "number"
          },
          "total": {
            "type": "number"
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "price": {
            "type": "number"
          },
          "promoPrice": {
            "type": "number",
            "nullable": true
          },
          "stock": {
            "type": "integer"
          },
          "active": {
            "type": "boolean"
          }
        }
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "code": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "requested",
              "quoted",
              "contract_signed",
              "confirmed",
              "delivered",
              "collected",
              "disputed",
              "awaiting_payment",
              "closed",
              "cancelled"
            ]
          },
          "name": {
            "type": "string"
          },
          "eventDate": {
            "type": "string",
            "format": "date"
          },
          "guests": {
            "type": "integer"
          },
          "responsible": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "cpf": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              }
            }
          },
          "totals": {
            "type": "object",
            "properties": {
              "quote": {
                "type": "number"
              },
              "deposit": {
                "type": "number"
              },
              "consumed": {
                "type": "number"
              },
              "losses": {
                "type": "number"
              },
              "rental": {
                "type": "number"
              },
              "final": {
                "type": "number"
              },
              "paid": {
                "type": "number"
              },
              "balanceDue": {
                "type": "number"
              }
            }
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "product",
                    "equipment"
                  ]
                },
                "name": {
                  "type": "string"
                },
                "qtyRequested": {
                  "type": "integer"
                },
                "qtyDelivered": {
                  "type": "integer"
                },
                "qtyReturnedClosed": {
                  "type": "integer"
                },
                "qtyReturnedEmpty": {
                  "type": "integer"
                },
                "qtyBroken": {
                  "type": "integer"
                },
                "qtyMissing": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/token": {
      "post": {
        "tags": [
          "Autenticação"
        ],
        "summary": "Gerar token de acesso (válido por 1h)",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "grant_type",
                  "client_id",
                  "client_secret",
                  "username",
                  "password"
                ],
                "properties": {
                  "grant_type": {
                    "type": "string",
                    "example": "password"
                  },
                  "client_id": {
                    "type": "string"
                  },
                  "client_secret": {
                    "type": "string"
                  },
                  "username": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "access_token": {
                      "type": "string"
                    },
                    "token_type": {
                      "type": "string",
                      "example": "Bearer"
                    },
                    "expires_in": {
                      "type": "integer",
                      "example": 3600
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/orders": {
      "get": {
        "tags": [
          "Pedidos"
        ],
        "summary": "Listar pedidos da loja",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Um ou mais, separados por vírgula"
          },
          {
            "name": "updatedSince",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Order"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/orders/{id}": {
      "get": {
        "tags": [
          "Pedidos"
        ],
        "summary": "Detalhar pedido",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pedido"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/orders/{id}/status": {
      "put": {
        "tags": [
          "Pedidos"
        ],
        "summary": "Alterar status do pedido (dispara ORDER_STATUS_CHANGED)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "WAITING",
                      "APPROVED",
                      "IN_TRANSIT",
                      "DONE",
                      "REJECTED",
                      "HIDDEN"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pedido atualizado"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/products": {
      "get": {
        "tags": [
          "Produtos"
        ],
        "summary": "Listar catálogo",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Produtos"
          }
        }
      },
      "patch": {
        "tags": [
          "Produtos"
        ],
        "summary": "Sincronizar estoque/preço por SKU (até 1000 itens)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "sku": {
                      "type": "string"
                    },
                    "stock": {
                      "type": "integer"
                    },
                    "price": {
                      "type": "number"
                    },
                    "promoPrice": {
                      "type": "number"
                    },
                    "active": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resultado por SKU"
          }
        }
      }
    },
    "/v1/events": {
      "get": {
        "tags": [
          "Meu Evento (extensão)"
        ],
        "summary": "Listar eventos",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Eventos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Event"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/events/{id}": {
      "get": {
        "tags": [
          "Meu Evento (extensão)"
        ],
        "summary": "Detalhar evento com itens, contagem e pagamentos",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Evento"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  }
}