# -*- coding: utf-8 -*-
"""
Function: del_screen_shot.py moudle. This moudle mainly involves the
 deleting the System Screen Image on the Service Side function.
Copyright Information: xFusion Digital Technologies Co.,
 Ltd. All Rights Reserved © 2020-2021
"""


def delscreenshot_init(parser, parser_list):
    """
    delete screen snapshot file subcommand initialization
    Args:
              parser            : major command argparser
              parser_list       : save subcommand parser list
    Returns:
         delscreenshot
    Raises:
        None
    Examples:
         None
    Date:  2020.4.16
    """
    sub_parser = parser.add_parser('delscreenshot',
                                   help='''delete screenshot file''')

    parser_list['delscreenshot'] = sub_parser

    return 'delscreenshot'


def _respparse(resp):
    """
    parse response code and body
    Args:
              resp            (dic):   response information
    Returns:
         None
    Raises:
        None
    Examples:
         None
    Date:  2020.4.16
    """
    if resp['status_code'] == 200:
        print('Success: successfully completed request\r')
    else:
        msgs = resp['message']['error']['@Message.ExtendedInfo']
        message = msgs[0].get('Message').lower()
        print('Failure: %s' % message[:-1])


def delscreenshot(client, _):
    """
    delete screenshot file
    Args:
              client                 : RedfishClient object
    Returns:
         resp
    Raises:
        None
    Examples:
         None
    Date:  2020.4.16
    """
    slotid = client.get_slotid()
    if slotid is None:
        return None

    url = "/redfish/v1/Managers/%s/DiagnosticService" \
          "/Actions/DiagnosticService.DeleteScreenShot" \
          % slotid
    payload = {}
    resp = client.create_resource(url, payload)
    if resp is None:
        return None

    _respparse(resp)
    return resp
