# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html#aws-resource-init-commands
module CloudFormer

  module CloudFormation
    class ConfigSetItem < MetadataResource

      def initialize
        super
        @aws_type = 'AWS::CloudFormation::ConfigSet'
      end

      def commands(items=nil)
        @commands = items if items
        @commands
      end

      def files(items=nil)
        @files = items if items
        @files
      end

      def groups(items=nil)
        @groups = items if items
        @groups
      end

      def packages(items=nil)
        @packages = items if items
        @packages
      end

      def services(items=nil)
        @services = items if items
        @services
      end

      def sources(items=nil)
        @sources = items if items
        @sources
      end

      def users(items=nil)
        @users = items if items
        @users
      end

      def name(val=nil)
        @name = val if val
        @name
      end

      def dump_json
        res = {}
        %w(commands files groups packages services sources users).each do |type|
          vals = nil
          if instance_variable_defined?("@#{type}")
            vals = instance_variable_get("@#{type}")
          end
          if vals && vals.any?
            res[type] = {}
            vals.each do |val|
              res[type][val.name] = val.dump_json
            end
          end
        end
        res
      end
    end
  end
end
