module Devops
  module Model
    module ModelWithProvider

      class << self
        def included(mod)
          mod.field :provider, type: String

          mod.validates_presence_of :provider, message: "'provider' is undefined"
        end
      end

      def check_provider_type hash
        raise Devops::Exception::ParserError.new("Parameter 'provider' is not a string") unless hash["provider"].is_a?(String)
      end

      def validate_provider
        providers = Provider.providers
        errors.add(:provider, "Invalid provider, available values: '#{providers.join("', '")}'") unless providers.include?(self.provider)
      end

      def provider_hash
        {
          "provider" => self.provider
        }
      end

    end
  end
end

