import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401


def url_reputation():
    results = demisto.executeCommand('url', {'url': demisto.get(demisto.args(), 'url')})

    for item in results:
        if isError(item):
            if is_offset_error(item):  # call to is_offset_error is a temporary fix to ignore offset 1 error
                results.remove(item)
            else:
                item['Contents'] = item['Brand'] + ' returned an error.\n' + str(item['Contents'])

    demisto.results(results)


def is_offset_error(item) -> bool:
    '''error msg: 'Offset: 1' will not be displayed to Users
       This method is temporary and will be removed
       once XSUP-18208 issue is fixed.'''
    if item['Contents'] and 'Offset' in item['Contents']:
        return True
    return False


def main():
    url_reputation()


if __name__ in ('__main__', '__builtin__', 'builtins'):  # pragma: no cover
    main()
