{{>licenseInfo}}
// this model was generated using model.mustache
package {{modelPackage}}
{{#imports}}import {{import}}
{{/imports}}
import scala.util.control.NonFatal

// see https://com-lihaoyi.github.io/upickle/
import upickle.default.{ReadWriter => RW, macroRW}
import upickle.default.*

{{#models}}
{{#model}}
case class {{classname}}(
  {{#vars}}
  {{#description}}
/* {{{description}}} */
  {{/description}}
  {{name}}: {{#isEnum}}{{^required}}Option[{{/required}}{{classname}}.{{datatypeWithEnum}}{{^required}}]{{/required}}{{/isEnum}}{{^isEnum}}{{{vendorExtensions.x-datatype-model}}}{{/isEnum}}{{^required}} = {{{vendorExtensions.x-defaultValue-model}}} {{/required}}{{^-last}},{{/-last}}

  {{/vars}}) {

  def asJson: String = asData.asJson

  def asData : {{classname}}Data = {
    {{classname}}Data(
        {{#vars}}
            {{name}} = {{name}}{{#vendorExtensions.x-map-asModel}}.map(_.asData){{/vendorExtensions.x-map-asModel}}{{#vendorExtensions.x-wrap-in-optional}}.getOrElse({{{defaultValue}}}){{/vendorExtensions.x-wrap-in-optional}}{{^-last}},{{/-last}}
        {{/vars}}
    )
  }

}

object {{classname}}{

    given RW[{{classname}}] = {{classname}}Data.readWriter.bimap[{{classname}}](_.asData, _.asModel)

    enum Fields(fieldName : String) extends Field(fieldName) {
        {{#vars}}
            case {{name}} extends Fields("{{name}}")
        {{/vars}}
    }

{{#vars}}
    {{#isEnum}}
        // baseName={{{baseName}}}
        // nameInCamelCase = {{{nameInCamelCase}}}
        enum {{datatypeWithEnum}} derives ReadWriter {
        {{#_enum}}
            case {{.}}
        {{/_enum}}
        }
    {{/isEnum}}
{{/vars}}

}

{{/model}}
{{/models}}
