<commit_before>package drt.shared

import drt.shared.Terminals.{T2, T3, T5, Terminal}
import drt.shared.api.PassengerInfoSummary

import scala.collection.immutable.Map

object RedList {
  def redListOriginWorkloadExcluded(portCode: PortCode, terminal: Terminal): Boolean =
    portCode == PortCode("LHR") && List(T2, T5).contains(terminal)

  val countryToCode: Map[String, String] = Map(
    "Afghanistan" -> "AFG",
    "Angola" -> "AGO",
    "Argentina" -> "ARG",
    "Bahrain" -> "BHR",
    "Bangladesh" -> "BGD",
    "Bolivia" -> "BOL",
    "Botswana" -> "BWA",
    "Brazil" -> "BRA",
    "Burundi" -> "BDI",
    "Cape Verde" -> "CPV",
    "Chile" -> "CHL",
    "Colombia" -> "COL",
    "Costa Rica" -> "CRI",
    "Democratic Republic of the Congo" -> "COD",
    "Dominican Republic" -> "DOM",
    "Ecuador" -> "ECU",
    "Egypt" -> "EGY",
    "Eritrea" -> "ERI",
    "Eswatini" -> "SWZ",
    "Ethiopia" -> "ETH",
    "French Guiana" -> "GUF",
    "Guyana" -> "GUY",
    "Haiti" -> "HTI",
    "India" -> "IND",
    "Kenya" -> "KEN",
    "Lesotho" -> "LSO",
    "Malawi" -> "MWI",
    "Maldives" -> "MDV",
    "Mongolia" -> "MNG",
    "Mozambique" -> "MOZ",
    "Namibia" -> "NAM",
    "Nepal" -> "NPL",
    "Oman" -> "OMN",
    "Pakistan" -> "PAK",
    "Panama" -> "PAN",
    "Paraguay" -> "PRY",
    "Peru" -> "PER",
    "Philippines" -> "PHL",
    "Qatar" -> "QAT",
    "Rwanda" -> "RWA",
    "Seychelles" -> "SYC",
    "Somalia" -> "SOM",
    "South Africa" -> "ZAF",
    "Sri Lanka" -> "LKA",
    "Sudan" -> "SDN",
    "Suriname" -> "SUR",
    "Tanzania" -> "TZA",
    "Tunisia" -> "TUN",
    "Turkey" -> "TUR",
    "Trinidad and Tobago" -> "TTO",
    "Uganda" -> "UGA",
    "United Arab Emirates" -> "ARE",
    "Uruguay" -> "URY",
    "Venezuela" -> "VEN",
    "Zambia" -> "ZMB",
    "Zimbabwe" -> "ZWE",
  )
}


sealed trait DirectRedListFlight {
  val isRedListOrigin: Boolean
  val terminalDiversion: Boolean
  val outgoingDiversion: Boolean
  val incomingDiversion: Boolean
  val paxDiversion: Boolean = outgoingDiversion || incomingDiversion
}

case class LhrDirectRedListFlight(isRedListOrigin: Boolean,
                                  terminalDiversion: Boolean,
                                  outgoingDiversion: Boolean,
                                  incomingDiversion: Boolean) extends DirectRedListFlight

case class DefaultDirectRedListFlight(isRedListOrigin: Boolean) extends DirectRedListFlight {
  override val terminalDiversion: Boolean = false
  override val outgoingDiversion: Boolean = false
  override val incomingDiversion: Boolean = false
}

object DirectRedListFlight {
  def apply(portCode: PortCode, displayTerminal: Terminal, flightTerminal: Terminal, isRedListOrigin: Boolean): DirectRedListFlight = {
    val greenTerminal = portCode == PortCode("LHR") && List(T2, T3 ,T5).contains(displayTerminal)
    val terminalDiversion = displayTerminal != flightTerminal

    val outgoingDiversion =
      portCode == PortCode("LHR") && isRedListOrigin && greenTerminal
    val incomingDiversion =
      portCode == PortCode("LHR") && isRedListOrigin && terminalDiversion && !greenTerminal

    if (portCode == PortCode("LHR"))
      LhrDirectRedListFlight(isRedListOrigin, terminalDiversion, outgoingDiversion, incomingDiversion)
    else
      DefaultDirectRedListFlight(isRedListOrigin)
  }
}

sealed trait IndirectRedListPax {
  val isEnabled: Boolean
}

object IndirectRedListPax {
  def apply(displayRedListInfo: Boolean, portCode: PortCode, flightWithSplits: ApiFlightWithSplits, maybePassengerInfo: Option[PassengerInfoSummary]): IndirectRedListPax =
    (displayRedListInfo, portCode) match {
      case (false, _) => NoIndirectRedListPax
      case (true, PortCode("LHR")) =>
        NeboIndirectRedListPax(flightWithSplits.apiFlight.RedListPax)
      case (true, _) =>
        val maybeNats = maybePassengerInfo.map(_.nationalities.filter {
          case (nat, _) => redListNats.toList.contains(nat)
        })
        ApiIndirectRedListPax(maybeNats)
    }

  val redListNats: Iterable[Nationality] = RedList.countryToCode.values.map(Nationality(_))
}

sealed trait EnabledIndirectRedListPax extends IndirectRedListPax {
  override val isEnabled: Boolean = true
  val maybeCount: Option[Int]
}

case object NoIndirectRedListPax extends IndirectRedListPax {
  override val isEnabled: Boolean = false
}

case class ApiIndirectRedListPax(maybeNationalities: Option[Map[Nationality, Int]]) extends EnabledIndirectRedListPax {
  override val maybeCount: Option[Int] = maybeNationalities.map(_.values.sum)
}

case class NeboIndirectRedListPax(maybeCount: Option[Int]) extends EnabledIndirectRedListPax
<commit_msg>DRTII-862 adding Cuba, Indonesia, Myanmar and Sierra Leone to red list (#1155)<commit_after>package drt.shared

import drt.shared.Terminals.{T2, T3, T5, Terminal}
import drt.shared.api.PassengerInfoSummary

import scala.collection.immutable.Map

object RedList {
  def redListOriginWorkloadExcluded(portCode: PortCode, terminal: Terminal): Boolean =
    portCode == PortCode("LHR") && List(T2, T5).contains(terminal)

  val countryToCode: Map[String, String] = Map(
    "Afghanistan" -> "AFG",
    "Angola" -> "AGO",
    "Argentina" -> "ARG",
    "Bahrain" -> "BHR",
    "Bangladesh" -> "BGD",
    "Bolivia" -> "BOL",
    "Botswana" -> "BWA",
    "Brazil" -> "BRA",
    "Burundi" -> "BDI",
    "Cape Verde" -> "CPV",
    "Chile" -> "CHL",
    "Colombia" -> "COL",
    "Costa Rica" -> "CRI",
    "Cuba" -> "CUB",
    "Democratic Republic of the Congo" -> "COD",
    "Dominican Republic" -> "DOM",
    "Ecuador" -> "ECU",
    "Egypt" -> "EGY",
    "Eritrea" -> "ERI",
    "Eswatini" -> "SWZ",
    "Ethiopia" -> "ETH",
    "French Guiana" -> "GUF",
    "Guyana" -> "GUY",
    "Haiti" -> "HTI",
    "India" -> "IND",
    "Indonesia" -> "IDN",
    "Kenya" -> "KEN",
    "Lesotho" -> "LSO",
    "Malawi" -> "MWI",
    "Maldives" -> "MDV",
    "Mongolia" -> "MNG",
    "Mozambique" -> "MOZ",
    "Myanmar" -> "MMR",
    "Namibia" -> "NAM",
    "Nepal" -> "NPL",
    "Oman" -> "OMN",
    "Pakistan" -> "PAK",
    "Panama" -> "PAN",
    "Paraguay" -> "PRY",
    "Peru" -> "PER",
    "Philippines" -> "PHL",
    "Qatar" -> "QAT",
    "Rwanda" -> "RWA",
    "Seychelles" -> "SYC",
    "Sierra Leone" -> "SLE",
    "Somalia" -> "SOM",
    "South Africa" -> "ZAF",
    "Sri Lanka" -> "LKA",
    "Sudan" -> "SDN",
    "Suriname" -> "SUR",
    "Tanzania" -> "TZA",
    "Tunisia" -> "TUN",
    "Turkey" -> "TUR",
    "Trinidad and Tobago" -> "TTO",
    "Uganda" -> "UGA",
    "United Arab Emirates" -> "ARE",
    "Uruguay" -> "URY",
    "Venezuela" -> "VEN",
    "Zambia" -> "ZMB",
    "Zimbabwe" -> "ZWE",
  )
}


sealed trait DirectRedListFlight {
  val isRedListOrigin: Boolean
  val terminalDiversion: Boolean
  val outgoingDiversion: Boolean
  val incomingDiversion: Boolean
  val paxDiversion: Boolean = outgoingDiversion || incomingDiversion
}

case class LhrDirectRedListFlight(isRedListOrigin: Boolean,
                                  terminalDiversion: Boolean,
                                  outgoingDiversion: Boolean,
                                  incomingDiversion: Boolean) extends DirectRedListFlight

case class DefaultDirectRedListFlight(isRedListOrigin: Boolean) extends DirectRedListFlight {
  override val terminalDiversion: Boolean = false
  override val outgoingDiversion: Boolean = false
  override val incomingDiversion: Boolean = false
}

object DirectRedListFlight {
  def apply(portCode: PortCode, displayTerminal: Terminal, flightTerminal: Terminal, isRedListOrigin: Boolean): DirectRedListFlight = {
    val greenTerminal = portCode == PortCode("LHR") && List(T2, T3 ,T5).contains(displayTerminal)
    val terminalDiversion = displayTerminal != flightTerminal

    val outgoingDiversion =
      portCode == PortCode("LHR") && isRedListOrigin && greenTerminal
    val incomingDiversion =
      portCode == PortCode("LHR") && isRedListOrigin && terminalDiversion && !greenTerminal

    if (portCode == PortCode("LHR"))
      LhrDirectRedListFlight(isRedListOrigin, terminalDiversion, outgoingDiversion, incomingDiversion)
    else
      DefaultDirectRedListFlight(isRedListOrigin)
  }
}

sealed trait IndirectRedListPax {
  val isEnabled: Boolean
}

object IndirectRedListPax {
  def apply(displayRedListInfo: Boolean, portCode: PortCode, flightWithSplits: ApiFlightWithSplits, maybePassengerInfo: Option[PassengerInfoSummary]): IndirectRedListPax =
    (displayRedListInfo, portCode) match {
      case (false, _) => NoIndirectRedListPax
      case (true, PortCode("LHR")) =>
        NeboIndirectRedListPax(flightWithSplits.apiFlight.RedListPax)
      case (true, _) =>
        val maybeNats = maybePassengerInfo.map(_.nationalities.filter {
          case (nat, _) => redListNats.toList.contains(nat)
        })
        ApiIndirectRedListPax(maybeNats)
    }

  val redListNats: Iterable[Nationality] = RedList.countryToCode.values.map(Nationality(_))
}

sealed trait EnabledIndirectRedListPax extends IndirectRedListPax {
  override val isEnabled: Boolean = true
  val maybeCount: Option[Int]
}

case object NoIndirectRedListPax extends IndirectRedListPax {
  override val isEnabled: Boolean = false
}

case class ApiIndirectRedListPax(maybeNationalities: Option[Map[Nationality, Int]]) extends EnabledIndirectRedListPax {
  override val maybeCount: Option[Int] = maybeNationalities.map(_.values.sum)
}

case class NeboIndirectRedListPax(maybeCount: Option[Int]) extends EnabledIndirectRedListPax

{'fraction_non_alphanumeric': 0.14181703070591958, 'fraction_numerical': 0.002426928352854279, 'mean_word_length': 3.466540999057493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6605459', 'n_tokens_mistral': 3401, 'n_tokens_neox': 3303, 'n_words': 688}