{
  "openapi": "3.0.1",
  "info": {
    "title": "Locations API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.mercadoe.com"
    }
  ],
  "paths": {
    "/v1/locations": {
      "post": {
        "tags": [
          "Locations"
        ],
        "summary": "Create a location",
        "description": "Creates a new location by providing the Address, LocationType, Country, and other details.",
        "parameters": [
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "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"
                }
              }
            }
          }
        }
      }
    },
    "/v1/locations/{locationId}": {
      "put": {
        "tags": [
          "Locations"
        ],
        "summary": "Update a location based on the LocationId",
        "description": "Updates a location specified by its Id.",
        "parameters": [
          {
            "name": "locationId",
            "in": "path",
            "description": "",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "",
          "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"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Locations"
        ],
        "summary": "Get a location by Id",
        "description": "Retrieves information about a specific location with the given LocationId.",
        "parameters": [
          {
            "name": "locationId",
            "in": "path",
            "description": "the request id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetByIdResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Locations"
        ],
        "summary": "Delete a location",
        "description": "Deletes a location specified by its LocationId.",
        "parameters": [
          {
            "name": "locationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted",
            "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/locations/{locationId}/business-organizations": {
      "put": {
        "tags": [
          "Locations"
        ],
        "summary": "Delete a location from an associated business organization",
        "description": "Deletes a location from an associated business organization specified by its LocationId.",
        "parameters": [
          {
            "name": "locationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeleteBorgLocationCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "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"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BusinessOrganization": {
        "required": [
          "clientBusinessOrganizationId"
        ],
        "type": "object",
        "properties": {
          "clientBusinessOrganizationId": {
            "minLength": 1,
            "type": "string",
            "description": "Business organization id in the client's ERP"
          },
          "entityType": {
            "type": "string",
            "description": "Type of organizational structure. Example: Company, branch, department.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CompanyNationalRegistration": {
        "type": "object",
        "properties": {
          "number": {
            "type": "string",
            "description": "Document identification number",
            "nullable": true
          },
          "type": {
            "type": "string",
            "description": "Type of legal document used in the company national registration. Ex: CNPJ, IE, etc.",
            "nullable": true
          },
          "stateRegistrationNumber": {
            "type": "string",
            "description": "State registration number",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CreateCommand": {
        "required": [
          "address",
          "addressNumber",
          "city",
          "clientLocationId",
          "country",
          "neighborhood",
          "postalCode",
          "state"
        ],
        "type": "object",
        "properties": {
          "locationName": {
            "maxLength": 100,
            "type": "string",
            "description": "Location name"
          },
          "clientLocationId": {
            "maxLength": 20,
            "minLength": 1,
            "type": "string",
            "description": "Location code in the client's ERP"
          },
          "address": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Address"
          },
          "addressNumber": {
            "maxLength": 10,
            "minLength": 1,
            "type": "string",
            "description": "Address number"
          },
          "neighborhood": {
            "maxLength": 20,
            "minLength": 1,
            "type": "string",
            "description": "Neighborhood"
          },
          "complement": {
            "maxLength": 20,
            "type": "string",
            "description": "Address complement",
            "nullable": true
          },
          "city": {
            "maxLength": 30,
            "minLength": 1,
            "type": "string",
            "description": "City"
          },
          "state": {
            "maxLength": 5,
            "minLength": 1,
            "type": "string",
            "description": "State"
          },
          "postalCode": {
            "maxLength": 15,
            "minLength": 1,
            "type": "string",
            "description": "Postal code"
          },
          "country": {
            "maxLength": 5,
            "minLength": 1,
            "type": "string",
            "description": "Country"
          },
          "contact": {
            "maxLength": 30,
            "type": "string",
            "description": "Contact name",
            "nullable": true
          },
          "phoneNumber": {
            "maxLength": 18,
            "type": "string",
            "description": "Phone number",
            "nullable": true
          },
          "locationType": {
            "$ref": "#/components/schemas/LocationTypes"
          },
          "companyNationalRegistration": {
            "$ref": "#/components/schemas/CompanyNationalRegistration"
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganization"
            },
            "description": "List with the business organizations, consisting of the Company Code and the bussiness structure code and description."
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag to identify if the location is blocked.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CreateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "DeleteBorgLocationCommand": {
        "required": [
          "businessOrganizations"
        ],
        "type": "object",
        "properties": {
          "businessOrganizations": {
            "minItems": 1,
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganization"
            },
            "description": "List with the business organizations, consisting of the Company Code and the bussiness structure code and description."
          }
        },
        "additionalProperties": false
      },
      "DeleteResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "GetByIdResponse": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "integer",
            "description": "Me Location code",
            "format": "int32"
          },
          "locationName": {
            "type": "string",
            "description": "Location name",
            "nullable": true
          },
          "clientLocationId": {
            "type": "string",
            "description": "Location code in the client's ERP",
            "nullable": true
          },
          "address": {
            "type": "string",
            "description": "Address",
            "nullable": true
          },
          "addressNumber": {
            "type": "string",
            "description": "Address number",
            "nullable": true
          },
          "neighborhood": {
            "type": "string",
            "description": "Neighborhood",
            "nullable": true
          },
          "complement": {
            "type": "string",
            "description": "Address complement",
            "nullable": true
          },
          "city": {
            "type": "string",
            "description": "City",
            "nullable": true
          },
          "state": {
            "type": "string",
            "description": "State",
            "nullable": true
          },
          "postalCode": {
            "type": "string",
            "description": "Postal code",
            "nullable": true
          },
          "country": {
            "type": "string",
            "description": "Country",
            "nullable": true
          },
          "contact": {
            "type": "string",
            "description": "Contact name",
            "nullable": true
          },
          "phoneNumber": {
            "type": "string",
            "description": "Phone number",
            "nullable": true
          },
          "locationType": {
            "$ref": "#/components/schemas/LocationTypes"
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganization"
            },
            "description": "List with the business organizations, consisting of the Company Code and the bussiness structure code and description."
          },
          "companyNationalRegistration": {
            "$ref": "#/components/schemas/CompanyNationalRegistration"
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag to identify if the location is blocked.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "LocationTypes": {
        "enum": [
          "Unknown",
          "DeliveryPlace",
          "ShippingPlace",
          "InvoicingPlace",
          "BillingPlace",
          "ReceivingPlace",
          "CollectingPlace"
        ],
        "type": "string"
      },
      "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": {}
      },
      "UpdateCommand": {
        "type": "object",
        "properties": {
          "locationName": {
            "maxLength": 100,
            "type": "string",
            "description": "Location name",
            "nullable": true
          },
          "clientLocationId": {
            "maxLength": 20,
            "type": "string",
            "description": "Location code in the client's ERP",
            "nullable": true
          },
          "address": {
            "maxLength": 50,
            "type": "string",
            "description": "Address",
            "nullable": true
          },
          "addressNumber": {
            "maxLength": 10,
            "type": "string",
            "description": "Address number",
            "nullable": true
          },
          "neighborhood": {
            "maxLength": 20,
            "type": "string",
            "description": "Neighborhood",
            "nullable": true
          },
          "complement": {
            "maxLength": 20,
            "type": "string",
            "description": "Address complement",
            "nullable": true
          },
          "city": {
            "maxLength": 30,
            "type": "string",
            "description": "City",
            "nullable": true
          },
          "state": {
            "maxLength": 5,
            "type": "string",
            "description": "State",
            "nullable": true
          },
          "postalCode": {
            "maxLength": 15,
            "type": "string",
            "description": "Postal code",
            "nullable": true
          },
          "country": {
            "maxLength": 5,
            "type": "string",
            "description": "Country",
            "nullable": true
          },
          "contact": {
            "maxLength": 30,
            "type": "string",
            "description": "Contact name",
            "nullable": true
          },
          "phoneNumber": {
            "maxLength": 18,
            "type": "string",
            "description": "Phone number",
            "nullable": true
          },
          "locationType": {
            "$ref": "#/components/schemas/LocationTypes"
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganization"
            },
            "description": "List with the business organizations, consisting of the Company Code and the bussiness structure code and description."
          },
          "companyNationalRegistration": {
            "$ref": "#/components/schemas/CompanyNationalRegistration"
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag to identify if the location is blocked.",
            "nullable": true
          }
        },
        "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": []
    }
  ],
  "tags": [
    {
      "name": "Locations",
      "description": "Locations API"
    }
  ]
}