{
  "openapi": "3.1.0",
  "info": {
    "title": "Eazyle Partner API",
    "version": "1.0.0",
    "description": "REST API for third-party integrations with Eazyle. Supports API key and OAuth 2.0 authentication with scoped access to organization data.",
    "contact": {
      "email": "support@eazyle.com"
    }
  },
  "servers": [
    {
      "url": "https://app.eazyle.com/api/partner/v1",
      "description": "Production"
    }
  ],
  "security": [
    { "apiKey": [] },
    { "oauth2": [] }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "API key issued from the Eazyle integration settings. Can also be passed as a Bearer token in the Authorization header."
      },
      "oauth2": {
        "type": "oauth2",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "/api/partner/oauth/token",
            "scopes": {
              "clients.read": "Read customer records",
              "invoices.read": "Read invoices",
              "payroll.read": "Read payroll runs",
              "workforce.read": "Read employee records",
              "workforce.write": "Create or update employee records",
              "projects.read": "Read time entries",
              "projects.write": "Create time entries",
              "analytics.read": "Read analytics feeds"
            }
          }
        }
      }
    },
    "schemas": {
      "Meta": {
        "type": "object",
        "properties": {
          "count": { "type": "integer" },
          "environment": { "type": "string", "enum": ["live", "sandbox"] }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        }
      }
    },
    "parameters": {
      "limit": {
        "name": "limit",
        "in": "query",
        "schema": { "type": "integer", "default": 100, "maximum": 1000 },
        "description": "Maximum number of records to return."
      }
    }
  },
  "paths": {
    "/clients": {
      "get": {
        "summary": "List customers",
        "operationId": "listClients",
        "tags": ["Customers"],
        "security": [{ "apiKey": [] }, { "oauth2": ["clients.read"] }],
        "parameters": [{ "$ref": "#/components/parameters/limit" }],
        "responses": {
          "200": {
            "description": "Customer list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "type": "object" } },
                    "meta": { "$ref": "#/components/schemas/Meta" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/invoices": {
      "get": {
        "summary": "List invoices",
        "operationId": "listInvoices",
        "tags": ["Invoices"],
        "security": [{ "apiKey": [] }, { "oauth2": ["invoices.read"] }],
        "parameters": [{ "$ref": "#/components/parameters/limit" }],
        "responses": {
          "200": {
            "description": "Invoice list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "type": "object" } },
                    "meta": { "$ref": "#/components/schemas/Meta" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/payroll/runs": {
      "get": {
        "summary": "List payroll runs",
        "operationId": "listPayrollRuns",
        "tags": ["Payroll"],
        "security": [{ "apiKey": [] }, { "oauth2": ["payroll.read"] }],
        "parameters": [{ "$ref": "#/components/parameters/limit" }],
        "responses": {
          "200": {
            "description": "Payroll run list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "type": "object" } },
                    "meta": { "$ref": "#/components/schemas/Meta" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/analytics/feeds": {
      "get": {
        "summary": "List analytics feed catalog",
        "operationId": "listAnalyticsFeeds",
        "tags": ["Analytics"],
        "security": [{ "apiKey": [] }, { "oauth2": ["analytics.read"] }],
        "responses": {
          "200": {
            "description": "Analytics feed catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "type": "object" } },
                    "meta": { "$ref": "#/components/schemas/Meta" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/workforce/employees": {
      "get": {
        "summary": "List employees",
        "operationId": "listEmployees",
        "tags": ["Workforce"],
        "security": [{ "apiKey": [] }, { "oauth2": ["workforce.read"] }],
        "parameters": [{ "$ref": "#/components/parameters/limit" }],
        "responses": {
          "200": {
            "description": "Employee list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "type": "object" } },
                    "meta": { "$ref": "#/components/schemas/Meta" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      },
      "post": {
        "summary": "Import employees",
        "operationId": "importEmployees",
        "tags": ["Workforce"],
        "security": [{ "apiKey": [] }, { "oauth2": ["workforce.write"] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["employees"],
                "properties": {
                  "employees": {
                    "type": "array",
                    "items": { "type": "object" },
                    "description": "Array of employee records to import."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Import result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "simulated": { "type": "boolean" },
                    "insertedCount": { "type": "integer" },
                    "invalidCount": { "type": "integer" }
                  }
                }
              }
            }
          },
          "400": { "description": "Bad request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/workforce/time-entries": {
      "get": {
        "summary": "List time entries",
        "operationId": "listTimeEntries",
        "tags": ["Workforce"],
        "security": [{ "apiKey": [] }, { "oauth2": ["projects.read"] }],
        "parameters": [{ "$ref": "#/components/parameters/limit" }],
        "responses": {
          "200": {
            "description": "Time entry list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "type": "object" } },
                    "meta": { "$ref": "#/components/schemas/Meta" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      },
      "post": {
        "summary": "Import time entries",
        "operationId": "importTimeEntries",
        "tags": ["Workforce"],
        "security": [{ "apiKey": [] }, { "oauth2": ["projects.write"] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["entries"],
                "properties": {
                  "entries": {
                    "type": "array",
                    "items": { "type": "object" },
                    "description": "Array of time entry records to import."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Import result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "simulated": { "type": "boolean" },
                    "insertedCount": { "type": "integer" },
                    "invalidCount": { "type": "integer" }
                  }
                }
              }
            }
          },
          "400": { "description": "Bad request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    }
  }
}
