from parallels.core.reports.model.issue import Issue
from parallels.hosting_check import DomainWebService, WebProtocol, WEB_SIGNATURES
from parallels.hosting_check.checkers.website_availability_checker import WebsiteAvailabilityChecker


def check_site(
        target_domain, target_ip=None, target_protocol=WebProtocol.HTTP, target_relative_url='',
        source_domain=None, source_ip=None, source_protocol=None, source_relative_url=None,
        check_timeout=30, depth=4, skip_similar_links=False, messages=None
):
    """
    Check migrated site

    depth:
        While compare URLs checker collects links on page (which point to the same site)
        and also check each of them. The parameter defines how many links can be followed relative
        to the passed URL.

    skip_similar_links:
        So, for example if you have pages '/news/index.php' and
        'news/top-news.php', we consider that it is enough to check only one
        of them if param is True

    :type target_domain: str | unicode
    :type target_ip: str | unicode | None
    :type target_protocol: str | unicode
    :type target_relative_url: str | unicode
    :type source_domain: str | unicode | None
    :type source_ip: str | unicode | None
    :type source_protocol: str | unicode | None
    :type source_relative_url: str | unicode | None
    :type check_timeout: int
    :type depth: int
    :type skip_similar_links: bool
    :type messages: dict
    :rtype: list[parallels.hosting_check.DomainIssue]
    """
    domain_web_service = DomainWebService(
        target_domain, target_ip, target_protocol, target_relative_url,
        source_domain, source_ip, source_protocol, source_relative_url,
        signatures=WEB_SIGNATURES, www_alias_enabled=True
    )
    checker = WebsiteAvailabilityChecker(
        check_timeout=check_timeout, depth=depth, group_directories=skip_similar_links, messages=messages
    )
    return [Issue(issue.category, issue.severity, issue.problem) for issue in checker.check([domain_web_service])]
