require 'exceptions/non_existing_user'
module Validators
  class Helpers::Users < Base

    error_class ::Devops::NonExistingUser

    def valid?
      available_users = ::Devops::Db.connector.users_names(@model)
      @nonexistent_users = (@model || []) - available_users
      @nonexistent_users.empty?
    end

    def message
      Devops::Messages.t("project.deploy_env.validation.users.not_exist", users: @nonexistent_users.join("', '"))
    end
  end
end
