require 'heave/core'
require 'heave/hooks'

module Heave
  ##
  #
  #
  module DSL
    ##
    #
    #
    class StageConfigurator
      include Heave::Hooks

      def initialize(cfg)
        @cfg = cfg
      end

      def method_missing(m, *args, &block)
        if @cfg.respond_to?(m)
          @cfg.__send__(m, *args)
        else
          super
        end
      end
    end

    def deploy(stage, &block)
      stagename = (stage.nil? || stage == :global || stage == 'global') ? :deploy : stage.to_sym
      stagecfg = Heave::Config.new(stagename)
      stagecfg + Heave.config

      block.call(StageConfigurator.new(stagecfg))

      Heave.add_stage(stagename, Heave::Stage, stagecfg)
    end

    def heave
      Heave.config
    end
  end
end
