{
  "openapi": "3.0.1",
  "info": {
    "title": "Ledgers API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.mercadoe.com"
    }
  ],
  "paths": {
    "/v1/ledgers/business-organizations": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all ledger business organization joins",
        "description": "Get a list of all ledger accounts and business organizations that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllBusinessOrganizationsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers/cost-centers": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all ledger accounts x cost centers",
        "description": "Get a list of all ledger accounts with their related cost centers that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllCostCentersResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers/service-orders": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all ledger accounts x service orders",
        "description": "Get a list of all ledger accounts with their related service orders that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllServiceOrdersResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers": {
      "post": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Create a ledger",
        "description": "Create a new ledger account to register your transaction by providing the code, description, and other details, if applicable.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Get all ledger accounts",
        "description": "Get a list of all ledger accounts that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers/{code}": {
      "put": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Update a Ledger based on the Ledger account code",
        "description": "Change the specified fields of a Ledger Account with the provided values by informing the Ledger account code.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "description": "the Ledger account code",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers/{code}/relationships/delete": {
      "post": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Delete the Ledger relationships based on the Ledger account code",
        "description": "The Ledger Account has three relationships: Service Orders, Cost Centers, and Business Organizations.\r\nYou can delete one or more relationships of a Ledger Account with the provided values by informing the Ledger account code (`code` field).",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "description": "the Ledger account code",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeleteCommand"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "No Content",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers/{code}/relationships": {
      "put": {
        "tags": [
          "Ledgers Relationships"
        ],
        "summary": "Update the relationships between cost centers and service orders with ledgers.",
        "description": "Based on the ledger, remove existing relationships and add new ones according to the received payload.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "description": "The ledger code",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateRelationshipCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateRelationshipResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Ledgers Relationships"
        ],
        "summary": "Get all cost objects relationships by ledger code",
        "description": "Get a list of all cost objects relationships that are available to the connected user.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllRelationshipsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BusinessOrganizationMinimal": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "entityType": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "BusinessOrganizations": {
        "type": "object",
        "properties": {
          "code": {
            "maxLength": 50,
            "type": "string"
          },
          "entityType": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "CostCenterModel": {
        "type": "object",
        "properties": {
          "costCenter": {
            "maxLength": 20,
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "CreateCommand": {
        "required": [
          "code",
          "description",
          "isActive",
          "isBlocked",
          "isDeactivated"
        ],
        "type": "object",
        "properties": {
          "code": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Ledger account code"
          },
          "description": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Ledger account description"
          },
          "isActive": {
            "type": "boolean",
            "description": "Identifies if the ledger account is active (True/False)."
          },
          "isBlocked": {
            "type": "boolean",
            "description": "Identifies if the ledger account is blocked (True/False)."
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Identifies if the ledger account is deactivated (True/False)."
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllCostCentersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all cost centers are included",
            "nullable": true
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all service orders are included",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizations"
            },
            "description": "Business Organizations is a list consisting of the company code and the entity type fields.",
            "nullable": true
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterModel"
            },
            "description": "Cost centers is a list consisting of the `costCenter` field which is associated with that ledger account.",
            "nullable": true
          },
          "serviceOrders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceOrderModel"
            },
            "description": "Service orders is a list consisting of the service order fields (`clientOrderId` and `orderCategory`) which is associated with that ledger account.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CreateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "DeleteCommand": {
        "type": "object",
        "properties": {
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllCostCentersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all cost centers are included",
            "nullable": true
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all service orders are included",
            "nullable": true
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterModel"
            },
            "description": "Cost centers is a list consisting of the `costCenter` field which is associated with that ledger account.",
            "nullable": true
          },
          "serviceOrders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceOrderModel"
            },
            "description": "Service orders is a list consisting of the service order fields (`clientOrderId` and `orderCategory`) which is associated with that ledger account.",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizations"
            },
            "description": "Business Organizations is a list consisting of the company code and the entity type fields.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "DeleteResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "GetAllBusinessOrganizationsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllBusinessOrganizationsResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllBusinessOrganizationsResponseData": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Ledger account code"
          },
          "businessOrganization": {
            "$ref": "#/components/schemas/BusinessOrganizationMinimal"
          }
        },
        "additionalProperties": false
      },
      "GetAllCostCentersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllCostCentersResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllCostCentersResponseData": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Ledger account code"
          },
          "costCenter": {
            "$ref": "#/components/schemas/CostCenterModel"
          }
        },
        "additionalProperties": false
      },
      "GetAllRelationshipsData": {
        "type": "object",
        "properties": {
          "clientCostCenterId": {
            "type": "string",
            "description": "Cost center identifier"
          },
          "ledgerCode": {
            "type": "string",
            "description": "Ledger account code"
          },
          "clientOrderId": {
            "type": "string",
            "description": "The purchase order ID in the Client's ERP"
          },
          "clientOrderCategory": {
            "type": "string",
            "description": "Order category in the Client's ERP"
          }
        },
        "additionalProperties": false
      },
      "GetAllRelationshipsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllRelationshipsData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllResponseData": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Ledger account code"
          },
          "description": {
            "type": "string",
            "description": "Ledger account description",
            "nullable": true
          },
          "isActive": {
            "type": "boolean",
            "description": "Identifies if the ledger account is active (True/False).",
            "nullable": true
          },
          "isBlocked": {
            "type": "boolean",
            "description": "Identifies if the ledger account is blocked (True/False).",
            "nullable": true
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Identifies if the ledger account is deactivated (True/False).",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllServiceOrdersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllServiceOrdersResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllServiceOrdersResponseData": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Ledger account code"
          },
          "serviceOrder": {
            "$ref": "#/components/schemas/ServiceOrderMinimal"
          }
        },
        "additionalProperties": false
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": {}
      },
      "RelationshipModel": {
        "required": [
          "category",
          "clientOrderId",
          "costCenterId"
        ],
        "type": "object",
        "properties": {
          "costCenterId": {
            "minLength": 1,
            "type": "string"
          },
          "areCostCentersIncluded": {
            "type": "boolean"
          },
          "clientOrderId": {
            "minLength": 1,
            "type": "string"
          },
          "category": {
            "minLength": 1,
            "type": "string"
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean"
          }
        },
        "additionalProperties": false
      },
      "ServiceOrderMinimal": {
        "type": "object",
        "properties": {
          "order": {
            "type": "string"
          },
          "category": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "ServiceOrderModel": {
        "type": "object",
        "properties": {
          "clientOrderId": {
            "maxLength": 30,
            "type": "string"
          },
          "category": {
            "maxLength": 30,
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "UpdateCommand": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "description": "Ledger account description",
            "nullable": true
          },
          "isActive": {
            "type": "boolean",
            "description": "Identifies if the ledger account is active (True/False).",
            "nullable": true
          },
          "isBlocked": {
            "type": "boolean",
            "description": "Identifies if the ledger account is blocked (True/False).",
            "nullable": true
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Identifies if the ledger account is deactivated (True/False).",
            "nullable": true
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllCostCentersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all cost centers are included",
            "nullable": true
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all service orders are included",
            "nullable": true
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterModel"
            },
            "description": "Cost centers is a list consisting of the `costCenter` field which is associated with that ledger account.",
            "nullable": true
          },
          "serviceOrders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceOrderModel"
            },
            "description": "Service orders is a list consisting of the service order fields (`clientOrderId` and `orderCategory`) which is associated with that ledger account.",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizations"
            },
            "description": "Business Organizations is a list consisting of the company code and the entity type fields.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "UpdateRelationshipCommand": {
        "type": "object",
        "properties": {
          "relationships": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RelationshipModel"
            },
            "description": "Relationships with ledgers and service orders",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Ledger Relationships Command"
      },
      "UpdateRelationshipResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "UpdateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "Bearer": {
        "type": "apiKey",
        "description": "Please enter the word 'Bearer' followed by a space and then your JWT.",
        "name": "Authorization",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "Bearer": []
    }
  ]
}