Ensure pagerduty service exists.
    This method accepts as arguments everything defined in
    https://developer.pagerduty.com/documentation/rest/services/create

    Note that many arguments are mutually exclusive, depending on the "type" argument.

    Examples:

    .. code-block:: yaml

        # create a PagerDuty email service at test-email@DOMAIN.pagerduty.com
        ensure generic email service exists:
            pagerduty_service.present:
                - name: my email service
                - service:
                    description: "email service controlled by salt"
                    escalation_policy_id: "my escalation policy"
                    type: "generic_email"
                    service_key: "test-email"

    .. code-block:: yaml

        # create a pagerduty service using cloudwatch integration
        ensure my cloudwatch service exists:
            pagerduty_service.present:
                - name: my cloudwatch service
                - service:
                    escalation_policy_id: "my escalation policy"
                    type: aws_cloudwatch
                    description: "my cloudwatch service controlled by salt"

def present(profile='pagerduty', subdomain=None, api_key=None, **kwargs):
    '''
    Ensure pagerduty service exists.
    This method accepts as arguments everything defined in
    https://developer.pagerduty.com/documentation/rest/services/create

    Note that many arguments are mutually exclusive, depending on the "type" argument.

    Examples:

    .. code-block:: yaml

        # create a PagerDuty email service at test-email@DOMAIN.pagerduty.com
        ensure generic email service exists:
            pagerduty_service.present:
                - name: my email service
                - service:
                    description: "email service controlled by salt"
                    escalation_policy_id: "my escalation policy"
                    type: "generic_email"
                    service_key: "test-email"

    .. code-block:: yaml

        # create a pagerduty service using cloudwatch integration
        ensure my cloudwatch service exists:
            pagerduty_service.present:
                - name: my cloudwatch service
                - service:
                    escalation_policy_id: "my escalation policy"
                    type: aws_cloudwatch
                    description: "my cloudwatch service controlled by salt"

    '''
    # TODO: aws_cloudwatch type should be integrated with boto_sns
    # for convenience, we accept id, name, or email for users
    # and we accept the id or name for schedules
    kwargs['service']['name'] = kwargs['name']  # make args mirror PD API structure
    escalation_policy_id = kwargs['service']['escalation_policy_id']
    escalation_policy = __salt__['pagerduty_util.get_resource']('escalation_policies',
                                                                escalation_policy_id,
                                                                ['name', 'id'],
                                                                profile=profile,
                                                                subdomain=subdomain,
                                                                api_key=api_key)
    if escalation_policy:
        kwargs['service']['escalation_policy_id'] = escalation_policy['id']
    r = __salt__['pagerduty_util.resource_present']('services',
                                                    ['name', 'id'],
                                                    _diff,
                                                    profile,
                                                    subdomain,
                                                    api_key,
                                                    **kwargs)
    return r