require 'json'
require 'pry'
# The one command-line argument should be the path to the parameters.json file generated by parameters.rb
# Output is to stdout, so it should be redirected to a file if it needs to be saved
skips =
    [  "entity_axis_code",
        "record_cause_of_death"
    ]

parameter_file = File.read(ARGV[0])
parameters = JSON.parse(parameter_file)
puts "
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;

namespace VRDR
{
    /// <summary>Class
    /// <c>BaseMessage</c> is the base class of all messages.
    /// This partial class was automatically generated from https://github.com/nightingaleproject/vital_records_fhir_messaging_ig
    ///</summary>
    public partial class BaseMessage
    {
"
parameters.each { | variable, sliceinfo |
    case sliceinfo["type"]
        when "string"
            typeName = "String"
            type = "string"
            description = "string "
        when "unsignedInt"
            typeName = "UnsignedInt"
            type = "uint?"
            description = "uint "
        when "Coding"
            typeName = "Coding"
            type = "Dictionary<string, string>"
            description = "Coded value in Dictionary "
        else
            puts "uknown type" + " " + sliceinfo["type"]
            type = sliceinfo["type"]
    end
    slice = sliceinfo["slice"]
    part = sliceinfo["part"]
    path = "\"" + slice + "\""
    path = path + ", \"" + part + "\"" if part
    next if skips.member?(variable) || skips.member?(slice)  # these are special cases with manually written accessors
    puts "    /// <summary>#{variable}</summary>
    /// <value>#{description}</value>"
    puts "    public #{type} #{variable}
    {
      get
      {
          return GetParameter#{typeName}( #{path});
      }
      set
      {
            SetParameter#{typeName}(value, #{path});
      }
    }"
    }
puts "  }
}"
