#!/usr/bin/env python
#
# Change the telescope operating mode using the RESTful the API on a TART radio telescope
# Tim Molteno 2021 tim@elec.ac.nz
#
import argparse

from tart_tools.api_handler import AuthorizedAPIhandler

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Change telescope mode",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser.add_argument(
        "--api",
        required=False,
        default="https://tart.elec.ac.nz/signal",
        help="Telescope API server URL.",
    )
    parser.add_argument("--pw", default="password", type=str, help="API password")
    parser.add_argument("--mode", type=str, required=True, help="New mode (vis/raw)")

    ARGS = parser.parse_args()

    api = AuthorizedAPIhandler(ARGS.api, ARGS.pw)

    resp = api.post_payload_with_token(f"mode/{ARGS.mode}", {})
