require_relative "stack_template_base"
require_relative "stack_template_openstack"
require_relative "stack_template_aws"

module Devops
  module Model
    class StackTemplateFactory

      def self.create(provider, attrs)
        attrs['id'] ||= "#{provider}_stack_template_#{Time.new.to_i}"
        attrs['provider'] = provider
        st = get_class(provider).create(attrs)
      end

      def self.build_from(attrs)
        get_class(attrs['provider']).new(attrs)
      end

      def self.get_class(provider)
        case provider
          when 'openstack'
            StackTemplateOpenstack
          when 'aws'
            StackTemplateAws
          else
            raise InvalidRecord.new "Invalid provider: '#{provider}'"
        end
      end

    end
  end
end
