require 'db/mongo/models/stack/stack_base'

module Devops
  module Model
    class StackAws < StackBase

      def initialize attrs={}
        super
        self.provider = 'aws'
      end

      def update_in_cloud!(params)
        parameters = params.keep_if do |key|
          %w(Parameters TemplateURL Capabilities).include?(key)
        end

        provider_instance.update_stack(self, parameters)
      end

      # We should improve this functionality: stack will be rollbacked
      # if there are errors during stack_template changing, so we should track
      # that process and persist changes only in case of success.
      def change_stack_template!(stack_template)
        self.stack_template = stack_template
        update_in_cloud!('TemplateUrl' => stack_template_model.template_url)
        save
      end

    end
  end
end
