Let’s move on to the product model. Because we have already developed refined types, we can use them from the beginning here.
12
type ProductId = String Refined Uuid
final case class Product(id: ProductId, names: List[Translation])
Product model using UUID and a list of translations
Now, what is wrong with this?
If we look closely, we realize that a List may be empty. This is valid for a general-purpose list but not for our product, because we need at least one entry.
Luckily for us, the Cats library has us covered with the NonEmptyList data type. Including the JSON codecs for the product model, this leads us to our final implementation. Lastly, we should be using the existing UUID data type instead of coming up with our own refined string version — even when it seems cool.