from typing import Dict
from typing import Any
from warnings import warn


def has_license_and_update(data: Dict[str, Any]) -> bool:
  """Check if license header exists anywhere in notebook and format.

  Args:
    data: object representing a parsed JSON notebook.

  Returns:
    Boolean: True if notebook contains the license header, False if it doesn't.
  """
  has_license = False
  license_header = "#@title Licensed under the Apache License"

  for idx, cell in enumerate(data["cells"]):
    src_text = "".join(cell["source"])

    if license_header in src_text:
      has_license = True
      # Hide code pane from license form
      metadata = cell.get("metadata", {})
      metadata["cellView"] = "form"
      data["cells"][idx]["metadata"] = metadata

  if not has_license:
    warn(f"Missing license: {license_header}")

  return has_license