# -*- coding:utf-8 -*-
"""
Function: del_event_subscription.py moudle. This moudle mainly involves the
Deleting an Event Subscription function.
Copyright Information: xFusion Digital Technologies Co.,
 Ltd. All Rights Reserved © 2017-2020
"""
from scripts.common_function import REDFISH_STATUS_CODE_200
from scripts.common_function import REDFISH_STATUS_CODE_404


def deleventsubscription_init(parser, parser_dict):
    """
    Function Description:initializing the Command for
    Deleting an Event Subscription
    Parameter:parser object: action object
    parser_dict dict: dictionary format of subcommand and ArgumentParser
    """
    sub_parser = parser.add_parser('deleventsubs',
                                   help='''delete event subscription''')
    sub_parser.add_argument('-I', dest='Id', type=int, required=True,
                            help='''valid event subscription resource ID''')
    parser_dict['deleventsubs'] = sub_parser

    return 'deleventsubs'


def deleventsubscription(client, args):
    """
    Function Description: Deleting an Event Subscription
    Parameter:client refishClient: class object
    args object:CLI command
    """
    # Combine the URL of the resource to be deleted.
    event_id = args.Id
    url = '/redfish/v1/EventService/Subscriptions/%d' % event_id
    resp = client.delete_resource(url)
    if resp is None:
        return None
    if resp['status_code'] == REDFISH_STATUS_CODE_404:
        print('Failure: invalid resource ID for -I')
    elif resp['status_code'] == REDFISH_STATUS_CODE_200:
        print('Success: successfully completed request')

    return resp
