///|
fn consumer_manifest_json() -> String {
  let manifest =
    #|{
    #|  "name": "release-comms-kit",
    #|  "context": {
    #|    "product": {
    #|      "channel": "community"
    #|    }
    #|  },
    #|  "partials": {
    #|    "feature_list": "{{#highlights}}- {{.}}\n{{/highlights}}",
    #|    "footer": "--\nGenerated by a downstream package powered by moon-mustache.\n"
    #|  },
    #|  "profiles": {
    #|    "community": {
    #|      "context": {
    #|        "product": { "banner": "Community Edition" }
    #|      }
    #|    },
    #|    "enterprise": {
    #|      "context": {
    #|        "product": { "banner": "Enterprise Edition" }
    #|      },
    #|      "partials": {
    #|        "footer": "--\nGenerated for enterprise communication workflows.\n"
    #|      }
    #|    }
    #|  },
    #|  "files": [
    #|    {
    #|      "path": "release-notes.md",
    #|      "template": "# {{product.name}} {{product.version}}\n\n{{product.banner}}\n\n## Highlights\n{{> feature_list}}{{> footer}}"
    #|    },
    #|    {
    #|      "path": "announce-email.txt",
    #|      "template": "Subject: {{product.name}} {{product.version}} is live\n\nHello {{audience}},\n\nTop highlights:\n{{> feature_list}}{{> footer}}"
    #|    }
    #|  ]
    #|}
  manifest
}

///|
fn consumer_context() -> @src.Value {
  @src.Value::object({
    "product": @src.Value::object({
      "name": @src.Value::string("MoonDeploy"),
      "version": @src.Value::string("1.4.0"),
    }),
    "audience": @src.Value::string("maintainers"),
    "highlights": @src.Value::array([
      @src.Value::string("bundle profile support"),
      @src.Value::string("official spec reporting"),
      @src.Value::string("CI validation plans"),
    ]),
  })
}

///|
fn print_file(label : String, content : String) -> Unit {
  println("== " + label + " ==")
  println(content)
  println("")
}

///|
fn main {
  let manifest = @src.parse_bundle_manifest_json(consumer_manifest_json()).unwrap()
  let validation = @src.validate_bundle_manifest(manifest)
  let result = @src.render_bundle_manifest_checked(
    manifest,
    consumer_context(),
    @src.RenderOptions::strict(),
    profile_name="enterprise",
  ).unwrap()
  let plan = @src.build_bundle_plan("release-comms-kit", result, validation)
  println(
    @src.format_validation_report_markdown("release-comms-kit", validation),
  )
  println("")
  println(@src.format_bundle_plan_markdown(plan))
  println("")
  for file in result.files {
    print_file(file.path, file.output)
  }
}