from __future__ import annotations

import json


def register(subparsers) -> None:
    export_parser = subparsers.add_parser("export", help="导出客户数据")
    export_subparsers = export_parser.add_subparsers(dest="export_action", required=True)

    file_parser = export_subparsers.add_parser("file", help="导出到文件")
    file_parser.add_argument("--output", required=True)
    file_parser.add_argument("--json", dest="payload_json")
    file_parser.set_defaults(handler=handle_export_file)


def handle_export_file(args, service):
    payload = json.loads(args.payload_json) if args.payload_json else {}
    return service.export_customers(args.output, payload)
