#!/usr/bin/env python3
from __future__ import annotations

from _common import API_ROOT, api_request, build_auth_parser, dump, tenant_access_token


def main() -> int:
    parser = build_auth_parser("Get Feishu primary calendar")
    parser.add_argument("--user-open-id", default="")
    parser.add_argument("--user-id-type", default="open_id")
    args = parser.parse_args()
    token = tenant_access_token(args.app_id, args.app_secret)
    params = {"user_id_type": args.user_id_type}
    if args.user_open_id:
        params["open_id"] = args.user_open_id
    payload = api_request(
        "GET",
        f"{API_ROOT}/calendar/v4/calendars/primary",
        token=token,
        params=params,
    )
    dump(payload)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
