from __future__ import annotations

import json


def register(subparsers) -> None:
    reminder_parser = subparsers.add_parser("reminder", help="提醒规划与创建")
    reminder_subparsers = reminder_parser.add_subparsers(dest="reminder_action", required=True)

    plan_parser = reminder_subparsers.add_parser("plan", help="生成提醒计划")
    plan_parser.add_argument("--json", dest="payload_json", required=True)
    plan_parser.set_defaults(handler=handle_plan)

    schedule_parser = reminder_subparsers.add_parser("schedule", help="生成并注册提醒")
    schedule_parser.add_argument("--json", dest="payload_json", required=True)
    schedule_parser.set_defaults(handler=handle_schedule)


def handle_plan(args, service):
    return service.plan_reminders(json.loads(args.payload_json))


def handle_schedule(args, service):
    payload = json.loads(args.payload_json)
    payload["schedule"] = True
    return service.plan_reminders(payload)
