# -*- coding:utf-8 -*-
"""
Function: get_time.py moudle. This moudle mainly involves the
 querying the System Time function.
Copyright Information: xFusion Digital Technologies Co.,
 Ltd. All Rights Reserved © 2020-2021
"""
FORMAT = '%s: %s'


def gettime_init(parser, parser_list):
    """
    #==========================================================================
    # @Method: Register and obtain system time commands.
    # @Param: parser, major command argparser
    parser_list, save subcommand parser list
    # @Return:
    # @author:
    #==========================================================================
    """
    sub_parser = parser.add_parser('gettime',
                                   help='''get system time''')
    parser_list['gettime'] = sub_parser

    return 'gettime'


def gettime(client, _):
    """
    #==========================================================================
    # @Method: Obtain system time command processing functions.
    # @Param: client, RedfishClient object
    parser, subcommand argparser.
    Export error messages when parameters are incorrect.
    args, parameter list
    # @Return:
    # @author:
    # date:2017.08.29 11:02
    #==========================================================================
    """
    slotid = client.get_slotid()
    if slotid is None:
        return None

    url = "/redfish/v1/managers/%s" % slotid
    resp = client.get_resource(url)
    if resp is None:
        return None
    if resp['status_code'] == 200:
        print(FORMAT % ('DateTime', resp['resource'].get('DateTime', None)))
    elif resp['status_code'] == 404:
        print('Failure: resource was not found')

    return resp
