package io.flow.oneapi

case class Module(name: String, serviceNames: Seq[String])

object Module {

  val General = Module("general", Seq("common", "healthcheck", "organization", "search", "token", "user"))
  val Webhook = Module("webhook", Seq("webhook"))

  val All = Seq(
    Module("localization", Seq("catalog", "experience")),
    Module("pricing", Seq("currency")),
    Module("landed cost", Seq("harmonization")),
    Module("payment", Seq("payment")),
    Module("logistics", Seq("delivery_window", "fulfillment", "inventory", "label", "ratecard", "tracking")),
    Webhook,
    Module("customer service", Nil),
    Module("geolocation", Seq("location")),
    Module("reference", Seq("reference")),
    General
  )

  def findByServiceName(name: String): Option[Module] = {
    All.find(_.serviceNames.contains(name.toLowerCase))
  }

  def findByModuleName(name: String): Option[Module] = {
    All.find(_.name == name.toLowerCase)
  }

  def moduleSortIndex(name: String): Int = {
    val module = findByModuleName(name).getOrElse {
      sys.error(s"Invalid module[$name]")
    }

    val i = All.indexOf(module)
    assert(i >= 0, s"Could not find module: $module")
    i
  }
}

package io.flow.oneapi

case class Module(name: String, serviceNames: Seq[String])

object Module {

  val General = Module("general", Seq("common", "organization", "search", "token", "user"))
  val Webhook = Module("webhook", Seq("webhook"))

  val All = Seq(
    Module("localization", Seq("catalog", "experience")),
    Module("pricing", Seq("currency")),
    Module("landed cost", Seq("harmonization")),
    Module("payment", Seq("payment")),
    Module("logistics", Seq("delivery_window", "fulfillment", "inventory", "label", "ratecard", "tracking")),
    Webhook,
    Module("customer service", Nil),
    Module("geolocation", Seq("location")),
    Module("reference", Seq("reference")),
    General
  )

  def findByServiceName(name: String): Option[Module] = {
    All.find(_.serviceNames.contains(name.toLowerCase))
  }

  def findByModuleName(name: String): Option[Module] = {
    All.find(_.name == name.toLowerCase)
  }

  def moduleSortIndex(name: String): Int = {
    val module = findByModuleName(name).getOrElse {
      sys.error(s"Invalid module[$name]")
    }

    val i = All.indexOf(module)
    assert(i >= 0, s"Could not find module: $module")
    i
  }
}

--- 
+++ 
@@ -4,7 +4,7 @@
 
 object Module {
 
-  val General = Module("general", Seq("common", "organization", "search", "token", "user"))
+  val General = Module("general", Seq("common", "healthcheck", "organization", "search", "token", "user"))
   val Webhook = Module("webhook", Seq("webhook"))
 
   val All = Seq(
Add healthcheck to general module
