require 'stuka/internal/domain/process'

module Stuka

  class Validator

    attr_reader :message

    def process_valid?(process)
      
      Stuka::Process::ATTRS.each do |arg|
        result = process.public_send(arg.to_sym)
        if result.nil?
          @message = "#{process} does not all required attributes"
          return false
        end
      end

      Stuka::Process::REQUIRED_ATTRS.each do |arg|
        result = process.public_send(arg.to_sym)
        if result.nil? || result.empty?
          @mesasge = "#{process} has empty values of required attributes"
          return false 
        end
      end

      true
    end

    def process_set_valid?(processes)

      if processes.include? nil
        @message = "processes include nil"
        return false 
      end

      names = processes.map(&:name)
      
      if names.include?(nil) || names.include?("")
        @message = "some processes have no name or empty name"
        return false 
      end

      if names.uniq.length == names.length
        return true
      else
        @message = "multiple processes with same name defined"
        return false
      end
    end

  end

end