# -*- coding:utf-8 -*-
"""
Function: clear_sel.py moudle. This moudle mainly involves the
 clearing Logs function.
Copyright Information: xFusion Digital Technologies Co.,
 Ltd. All Rights Reserved © 2020-2021
"""


def clearsel_init(parser, parser_list):
    """
    #==========================================================================
    #   @Method:  Register functions to register methods used for clearing logs.
    #   @Param:   parser       major command argparser
                  parser_list   save subcommand parser list
    #   @Return:  none
    #   @author:
    #==========================================================================
    """
    sub_parser = parser.add_parser('clrsel', help='''clear SEL record''')
    parser_list['clrsel'] = sub_parser

    return 'clrsel'


def clearsel(client, _):
    """
    #==========================================================================
    #   @Method:  Clear logs.
    #   @Param:   client  RedfishClient object
                  parser  subcommand argparser.
                          Export error messages when parameters are incorrect.
                  args    parameter list
    #   @Return:
    #   @author:
    #==========================================================================
    """
    slotid = client.get_slotid()
    if slotid is None:
        return None
    url = "/redfish/v1/Systems/" + slotid + \
          "/LogServices/Log1/Actions/LogService.ClearLog"
    payload = {}

    resp = client.create_resource(url, payload)

    if resp is None:
        return None
    if resp['status_code'] == 200:
        print('Success: successfully completed request')

    return resp
