# -*- encoding: utf-8 -*-
"""
dws.app.cli.commands.did.keri.resolve module

"""

import argparse

from dws import log_name, ogler, set_log_level
from dws.core.didkeri import KeriResolver

parser = argparse.ArgumentParser(description='Resolve a did:keri DID')
parser.set_defaults(handler=lambda args: handler(args), transferable=True)
parser.add_argument('-n', '--name', action='store', default='dws', help='Name of controller.')
parser.add_argument(
    '--base', '-b', help='additional optional prefix to file location of KERI keystore', required=False, default=''
)
# passcode => bran
parser.add_argument(
    '--passcode', help='22 character encryption passcode for keystore (is not saved)', dest='bran', default=None
)
parser.add_argument('-c', '--config-dir', dest='config_dir', default=None, help='directory override for configuration data')
parser.add_argument('--config-file', dest='config_file', action='store', default=None, help='configuration filename override')
parser.add_argument('--did', '-d', help='DID to resolve (did:keri method)', required=True)
parser.add_argument('--oobi', '-o', help='OOBI to use for resolving the DID', required=False)
parser.add_argument(
    '--meta',
    '-m',
    help='Whether to include metadata or only return the DID document',
    action='store_true',
    required=False,
    default=False,
)
parser.add_argument(
    '-v',
    '--verbose',
    action='store_true',
    required=False,
    default=False,
    help='Show the verbose output of DID resolution',
)
parser.add_argument(
    '--loglevel',
    action='store',
    required=False,
    default='CRITICAL',
    help='Set log level to DEBUG | INFO | WARNING | ERROR | CRITICAL. Default is CRITICAL',
)

logger = ogler.getLogger(log_name)


def handler(args):
    """Creates the list of doers that handles command line did:keri DID doc  resolutions"""
    set_log_level(args.loglevel, logger)
    name = 'dws' if args.name is None or args.name == '' else args.name
    return [
        KeriResolver(
            did=args.did,
            oobi=args.oobi,
            meta=args.meta,
            verbose=args.verbose,
            name=name,
            base=args.base,
            bran=args.bran,
            config_file=args.config_file,
            config_dir=args.config_dir,
        )
    ]
