"""
Practice: handle an AI incident the way Lab 17's scripts 04 and 05 do. Rate its severity from
facts with the policy's table, score two rating methods against the policy, start the
notification clocks, and turn a vendor's questionnaire answers into a decision.

Fill in the TODOs, then run the tests:
    pytest test_incident_practice.py        (locally)
or press "Run tests" on the chapter page.
"""
from datetime import datetime, timedelta

RANK = {"P1": 1, "P2": 2, "P3": 3, "P4": 4}


def severity(f: dict) -> str:
    """The company's severity policy, applied to an incident's facts (a dict with the keys
    physical_harm, discrimination, personal_data_exposed, special_or_financial_data,
    people_affected, money_usd, wrong_commitment, public, reached_users):
      P1  physical_harm, or discrimination, or special_or_financial_data, or more than 10,000 people
      P2  personal_data_exposed, or more than $10,000, or wrong_commitment, or public,
          or more than 1,000 people
      P3  reached_users, or any money lost
      P4  anything else (nothing reached users)
    The first level whose condition holds wins."""
    # TODO
    raise NotImplementedError


def score(ratings: list[str], gold: list[str]) -> dict:
    """ratings and gold: one severity per report, same order. Count:
      right     ratings equal to the policy's level
      too_low   ratings less severe than the policy's (P2 for a P1): the people who must know don't
      too_high  ratings more severe than the policy's (P1 for a P2): an extra phone call
      p1_found  P1 reports rated P1"""
    # TODO
    raise NotImplementedError


def changed_across_tries(runs: list[list[str]]) -> int:
    """runs: the same reports rated on several tries (one list per try). How many reports got
    more than one different rating across the tries?"""
    # TODO
    raise NotImplementedError


def add_business_days(d: datetime, n: int) -> datetime:
    """n business days after d: step one day at a time, counting only Monday to Friday.
    The time of day stays the same. Public holidays aren't modeled."""
    # TODO
    raise NotImplementedError


def clocks(aware: datetime) -> dict:
    """A breach of EU customers' personal data at a US-listed company, decided material when
    the company became aware. Return:
      gdpr  the EU supervisory authority: 72 hours after aware, weekend included
      sec   the SEC's Form 8-K: 4 business days after aware"""
    # TODO
    raise NotImplementedError


def decide(answers: dict, rules: dict) -> tuple[str, list[str], list[str]]:
    """answers: question -> the vendor's answer. rules: question -> {answer: "blocker" | "condition"};
    an answer not listed is fine. Return (decision, blockers, conditions), with the questions in
    the answers' order:
      "reject" if any blocker, else "approve with conditions" if any condition, else "approve"."""
    # TODO
    raise NotImplementedError
