{
  "openapi": "3.1.0",
  "info": {
    "title": "TV Reorder",
    "version": "1.0.0",
    "description": "Public shared Samsung channel ordering; instructions at /guide. Prefer the HD equivalent and park matching plain/SD copies last. Keep services without HD twins."
  },
  "servers": [
    {
      "url": "https://tvreorder.cristi8.net"
    }
  ],
  "paths": {
    "/api/current": {
      "get": {
        "operationId": "getCurrentLineup",
        "summary": "Discover the current export and tuner keys",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "filename": {
                      "type": "string"
                    },
                    "tuners": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "tuner": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "revision": {
                            "type": "integer"
                          },
                          "count": {
                            "type": "integer"
                          }
                        },
                        "required": []
                      }
                    }
                  },
                  "required": []
                }
              }
            }
          },
          "409": {
            "description": "Revision conflict: read channels again"
          }
        }
      }
    },
    "/api/channels": {
      "get": {
        "operationId": "findChannels",
        "summary": "List channels in viewing order; use q to search and nextOffset to continue",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Exact SHA-256 ID of the TV export"
                    },
                    "tuner": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "nextOffset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "channels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "kind": {
                            "type": "string"
                          },
                          "quality": {
                            "type": "string"
                          },
                          "width": {
                            "type": "integer"
                          },
                          "height": {
                            "type": "integer"
                          },
                          "serviceType": {
                            "type": "integer"
                          },
                          "original": {
                            "type": "integer"
                          },
                          "number": {
                            "type": "integer"
                          },
                          "hdAlternativeId": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Preferred HD or UHD service ID within this tuner for a matching lower-quality copy."
                          }
                        },
                        "required": []
                      }
                    }
                  },
                  "required": []
                }
              }
            }
          },
          "409": {
            "description": "Revision conflict: read channels again"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tuner",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "quality",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    },
    "/api/order": {
      "post": {
        "operationId": "placeChannelGroups",
        "summary": "Preview or apply consecutive channel groups at a number or the end",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Exact SHA-256 ID of the TV export"
                    },
                    "tuner": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "integer"
                    },
                    "changed": {
                      "type": "integer"
                    },
                    "saved": {
                      "type": "boolean"
                    },
                    "examples": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "from": {
                            "type": "integer"
                          },
                          "to": {
                            "type": "integer"
                          }
                        },
                        "required": []
                      }
                    }
                  },
                  "required": []
                }
              }
            }
          },
          "409": {
            "description": "Revision conflict: read channels again"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Exact SHA-256 ID of the TV export"
                  },
                  "tuner": {
                    "type": "string"
                  },
                  "revision": {
                    "type": "integer"
                  },
                  "ops": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ids": {
                              "type": "array",
                              "items": {
                                "type": "string",
                                "description": "Service ID, kept as a decimal string"
                              }
                            },
                            "start": {
                              "oneOf": [
                                {
                                  "type": "integer",
                                  "minimum": 1,
                                  "maximum": 99999
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "end"
                                  ]
                                }
                              ]
                            }
                          },
                          "required": [
                            "ids",
                            "start"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "preferHd": {
                              "type": "boolean",
                              "enum": [
                                true
                              ]
                            }
                          },
                          "required": [
                            "preferHd"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    }
                  },
                  "preview": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "id",
                  "tuner",
                  "revision",
                  "ops",
                  "preview"
                ]
              }
            }
          }
        }
      }
    },
    "/api/undo": {
      "post": {
        "operationId": "undoLatestOrder",
        "summary": "Restore the preceding order for one tuner",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Exact SHA-256 ID of the TV export"
                    },
                    "tuner": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "integer"
                    }
                  },
                  "required": []
                }
              }
            }
          },
          "409": {
            "description": "Revision conflict: read channels again"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Exact SHA-256 ID of the TV export"
                  },
                  "tuner": {
                    "type": "string"
                  },
                  "revision": {
                    "type": "integer"
                  }
                },
                "required": [
                  "id",
                  "tuner",
                  "revision"
                ]
              }
            }
          }
        }
      }
    }
  }
}
