from parallels.core import get_logger
from parallels.core.reports.model.issue import Issue
from parallels.core.utils.common import is_empty, safe_format
from parallels.core import messages

logger = get_logger(__name__)


def log_issues(issues):
    """
    :type issues: list[parallels.core.reports.model.issue.Issue] | None
    :rtype: None
    """
    if issues is None:
        return

    for issue in issues:
        issue_str = issue.problem_text
        if not is_empty(issue.solution_text):
            issue_str += "\n\n" + safe_format(messages.ISSUE_SOLUTION, solution=issue.solution_text)
        if not is_empty(issue.details_text):
            issue_str += "\n\n" + safe_format(messages.ISSUE_DETAILS, details=issue.details_text)

        if issue.severity == Issue.SEVERITY_WARNING:
            logger.warning(issue_str)
        elif issue.severity == Issue.SEVERITY_ERROR:
            logger.error(issue_str)
        else:
            logger.info(issue_str)
