{
  "openapi": "3.1.0",
  "info": {
    "title": "NexaPilot API",
    "version": "1.0.0",
    "description": "REST API for NexaPilot accounts-receivable software: customers, invoices, payments and payment promises. Available on the Business plan. Create an API key in Settings → Developers. Docs: https://nexapilot.xyz/developers",
    "contact": {
      "email": "support@nexapilot.xyz",
      "url": "https://nexapilot.xyz/developers"
    }
  },
  "servers": [
    {
      "url": "https://hynulduftdkfukmviljj.supabase.co/functions/v1/api"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key starting with np_live_"
      }
    },
    "schemas": {
      "Customer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "company": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "NewCustomer": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "company": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "Invoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "number": {
            "type": "string"
          },
          "issue_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "amount": {
            "type": "number"
          },
          "currency": {
            "type": "string",
            "enum": [
              "TRY",
              "USD",
              "EUR"
            ]
          },
          "paid": {
            "type": "number"
          },
          "balance": {
            "type": "number"
          },
          "computed_status": {
            "type": "string",
            "enum": [
              "open",
              "partial",
              "overdue",
              "paid",
              "cancelled"
            ]
          },
          "days_overdue": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "NewInvoice": {
        "type": "object",
        "required": [
          "customer_id",
          "number",
          "due_date",
          "amount"
        ],
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "number": {
            "type": "string"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "amount": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "currency": {
            "type": "string",
            "enum": [
              "TRY",
              "USD",
              "EUR"
            ]
          },
          "notes": {
            "type": "string"
          },
          "payment_link": {
            "type": "string",
            "format": "uri",
            "description": "Must start with https://"
          }
        }
      },
      "NewPayment": {
        "type": "object",
        "required": [
          "invoice_id",
          "amount"
        ],
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "amount": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "paid_at": {
            "type": "string",
            "format": "date"
          },
          "method": {
            "type": "string"
          },
          "note": {
            "type": "string"
          }
        }
      },
      "Promise": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "amount": {
            "type": "number"
          },
          "currency": {
            "type": "string"
          },
          "promised_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "description": "e.g. pending, fulfilled or broken"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/customers": {
      "get": {
        "summary": "List customers",
        "operationId": "listCustomers",
        "responses": {
          "200": {
            "description": "Customers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Customer"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a customer",
        "operationId": "createCustomer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewCustomer"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invoices": {
      "get": {
        "summary": "List invoices with paid amount, balance and status",
        "operationId": "listInvoices",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "partial",
                "overdue",
                "paid",
                "cancelled"
              ]
            },
            "description": "Filter by computed status"
          }
        ],
        "responses": {
          "200": {
            "description": "Invoices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Invoice"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an invoice",
        "operationId": "createInvoice",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewInvoice"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/payments": {
      "post": {
        "summary": "Record a payment against an invoice",
        "operationId": "createPayment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewPayment"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/promises": {
      "get": {
        "summary": "List payment promises and their status",
        "operationId": "listPromises",
        "responses": {
          "200": {
            "description": "Promises",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Promise"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "security": [],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}