{
  "openapi": "3.0.1",
  "info": {
    "title": "api/time-slots/terminals",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "/"
    },
    {
      "url": "https://api.ati.su"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/gw/timeslots/api/v1/terminal": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Terminal"
              },
              "examples": {
                "Create Terminal": {
                  "value": {
                    "name": "Тестовая площадка",
                    "gates_count": "3",
                    "loading_type": "any",
                    "warehouse": 24540,
                    "schedule": [
                      {
                        "time_from": "00:00",
                        "time_to": "23:59",
                        "day_of_week": "1"
                      }
                    ],
                    "contacts": [
                      {
                        "name": "Имя менеджера склада",
                        "phone": "+7 000 000-00-00",
                        "country_phone_id": "0",
                        "warehouse": 34824
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Возвращается созданная или обновленная площадка погрузки-выгрузки",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "result": {
                      "type": "object",
                      "properties": {
                        "terminal": {
                          "$ref": "#/components/schemas/Terminal"
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "Terminal Created": {
                    "value": {
                      "ok": true,
                      "result": {
                        "terminal": {
                          "id": 35262,
                          "gates": [],
                          "schedule": [
                            {
                              "day_of_week": "1",
                              "time_from": "00:00:00",
                              "time_to": "23:59:00"
                            }
                          ],
                          "contacts": [
                            {
                              "id": 35498,
                              "name": "Имя менеджера склада",
                              "phone": "+7 000 000-00-00",
                              "country_phone_id": "0"
                            }
                          ],
                          "name": "Тестовая площадка",
                          "gates_count": 3,
                          "loading_type": "any",
                          "date_creation": "2023-07-04T08:09:18.676843+03:00",
                          "date_modified": "2023-07-04T08:09:18.676871+03:00",
                          "deleted": false,
                          "is_test": true,
                          "warehouse": 34824
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка валидации. Возникает, когда в какое-то из полей передано недопустимое значение",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/SingleError"
                    },
                    {
                      "$ref": "#/components/schemas/MultipleError"
                    }
                  ]
                },
                "examples": {
                  "Validation Errors": {
                    "value": {
                      "error": "multiple_errors",
                      "error_list": [
                        {
                          "error": "loading_type",
                          "reason": "Значения test нет среди допустимых вариантов."
                        },
                        {
                          "error": "warehouse",
                          "reason": "Некорректный тип. Ожидалось значение первичного ключа, получен str."
                        }
                      ],
                      "reason": "invalid"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "responses": {
          "200": {
            "description": "Возвращаются площадки погрузки-выгрузки",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "result": {
                      "type": "object",
                      "properties": {
                        "count": {
                          "type": "integer"
                        },
                        "terminals": {
                          "type": "array",
                          "description": "Список терминалов",
                          "items": {
                            "$ref": "#/components/schemas/Terminal"
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "Returned Terminals": {
                    "value": {
                      "ok": true,
                      "result": {
                        "count": 2,
                        "terminals": [
                          {
                            "id": 35260,
                            "gates": [],
                            "schedule": [
                              {
                                "day_of_week": "1",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              },
                              {
                                "day_of_week": "2",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              },
                              {
                                "day_of_week": "3",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              },
                              {
                                "day_of_week": "4",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              },
                              {
                                "day_of_week": "5",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              },
                              {
                                "day_of_week": "6",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              },
                              {
                                "day_of_week": "7",
                                "time_from": "00:00:00",
                                "time_to": "23:59:00"
                              }
                            ],
                            "contacts": [
                              {
                                "id": 35496,
                                "name": "Имя менеджера склада",
                                "phone": "+7 000 000-00-00",
                                "country_phone_id": "0"
                              }
                            ],
                            "name": "Площадка",
                            "gates_count": 1,
                            "loading_type": "any",
                            "date_creation": "2023-07-04T07:45:11.954912+03:00",
                            "date_modified": "2023-07-04T07:45:11.954929+03:00",
                            "deleted": false,
                            "is_test": false,
                            "warehouse": 34824
                          },
                          {
                            "id": 35259,
                            "gates": [],
                            "schedule": [],
                            "contacts": [],
                            "name": "Площадка",
                            "gates_count": 1,
                            "loading_type": "any",
                            "date_creation": "2023-07-04T06:57:45.340826+03:00",
                            "date_modified": "2023-07-04T07:34:58.968527+03:00",
                            "deleted": true,
                            "is_test": false,
                            "warehouse": 34823
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "terminal_ids": {
                    "type": "list",
                    "description": "Список удаляемых площадок погрузки-выгрузки",
                    "items": {
                      "type": "integer",
                      "description": "Идентификатор площадки погрузки-выгрузки"
                    }
                  }
                },
                "required": [
                  "terminal_ids"
                ]
              },
              "examples": {
                "Delete terminals": {
                  "value": {
                    "terminal_ids": [
                      35262
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Возвращается список удаленных площадок погрузки-выгрузки, а также списки ошибок, если таковые возникли",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "result": {
                      "type": "object",
                      "properties": {
                        "200": {
                          "type": "array",
                          "description": "Список идентификаторов удаленных площадок погрузки-выгрузки",
                          "items": {
                            "type": "integer",
                            "description": "Идентификатор площадки погрузки-выгрузки"
                          }
                        },
                        "400": {
                          "type": "array",
                          "description": "Список идентификаторов складов, при удалении которых возникли ошибки валидации",
                          "items": {
                            "type": "integer",
                            "description": "Идентификатор склада"
                          }
                        },
                        "500": {
                          "type": "array",
                          "description": "Список идентификаторов складов, при удалении которых возникли ошибки сервера",
                          "items": {
                            "type": "integer",
                            "description": "Идентификатор склада"
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "Terminals Deleted": {
                    "value": {
                      "ok": true,
                      "result": {
                        "200": [
                          35262
                        ],
                        "400": [],
                        "500": []
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка валидации. Возникает, когда в какое-то из полей передано недопустимое значение",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SingleError"
                },
                "examples": {
                  "Validation Error": {
                    "value": {
                      "error": "bad request",
                      "reason": "Необходимо передать список terminal_ids",
                      "details": null
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ScheduleItem": {
        "type": "object",
        "properties": {
          "time_from": {
            "type": "string",
            "required": "true",
            "description": "Время начала работы склада"
          },
          "time_to": {
            "type": "string",
            "description": "Время окончания работы склада",
            "required": "true"
          },
          "day_of_week": {
            "type": "integer",
            "description": "Идентификатор дня недели. 1-Понедельник, 2-Вторник, 3-Среда и т. д.",
            "required": "true",
            "minimum": 1,
            "maximum": 7
          }
        },
        "required": [
          "time_from",
          "time_to",
          "day_of_week"
        ]
      },
      "LoadingType": {
        "type": "string",
        "enum": [
          "any",
          "gates",
          "up",
          "lateral"
        ],
        "description": "Тип загрузки"
      },
      "WarehouseContact": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Идентификатор контакта во временных окнах"
          },
          "name": {
            "type": "string",
            "description": "Имя контактного лица",
            "required": "true"
          },
          "phone": {
            "type": "string",
            "description": "Телефон контактного лица",
            "required": "true"
          },
          "country_phone_id": {
            "type": "integer",
            "description": "Идентификатор страны телефона контактного лица. 0-Россия, 1-Украина, 2-Казахстан, 3-Беларусь, 4-Другие",
            "required": "true",
            "minimum": 0,
            "maximum": 4
          }
        },
        "required": [
          "name",
          "phone",
          "country_phone_id"
        ]
      },
      "Gate": {
        "type": "object"
      },
      "Terminal": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Идентификатор площадки погрузки-выгрузки"
          },
          "gates": {
            "type": "array",
            "description": "Список ворот площадки погрузки-выгрузки",
            "items": {
              "$ref": "#/components/schemas/Gate"
            }
          },
          "schedule": {
            "type": "array",
            "description": "Расписание работы площадки погрузки-выгрузки",
            "items": {
              "$ref": "#/components/schemas/ScheduleItem"
            }
          },
          "contacts": {
            "description": "Контактные данные ответственных лиц",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WarehouseContact"
            }
          },
          "name": {
            "type": "string",
            "description": "Название площадки погрузки-выгрузки"
          },
          "gates_count": {
            "type": "integer",
            "description": "Количество ворот"
          },
          "loading_type": {
            "$ref": "#/components/schemas/LoadingType"
          },
          "date_creation": {
            "type": "string",
            "description": "Дата создания площадки погрузки-выгрузки"
          },
          "date_modified": {
            "type": "string",
            "description": "Дата изменения площадки погрузки-выгрузки"
          },
          "deleted": {
            "description": "Флаг, указывающий существует ли площадка погрузки-выгрузки или была удалена",
            "type": "boolean"
          },
          "is_test": {
            "description": "Флаг, указывающий является ли площадка погрузки-выгрузки тестовой",
            "type": "boolean"
          },
          "warehouse": {
            "type": "integer",
            "description": "Идентификатор склада"
          }
        },
        "required": [
          "gates_count",
          "loading_type",
          "contacts",
          "name",
          "schedule",
          "warehouse"
        ]
      },
      "SingleError": {
        "description": "Одиночная ошибка",
        "properties": {
          "error": {
            "description": "Текстовый код ошибки",
            "type": "string"
          },
          "reason": {
            "description": "Человекочитаемый текст ошибки",
            "type": "string"
          }
        }
      },
      "MultipleError": {
        "type": "object",
        "description": "Множественная ошибка",
        "properties": {
          "error": {
            "description": "Текстовый код ошибки",
            "type": "string"
          },
          "reason": {
            "description": "Человекочитаемый текст ошибки",
            "type": "string"
          },
          "error_list": {
            "description": "Список возникших ошибок",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SingleError"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Authorization: Bearer {authorizationToken}"
      }
    }
  }
}