require 'dldap/connection'

module Dldap

  class Base
    include ActiveModel::Validations
    include ActiveModel::Serializers::JSON
    include ActiveModel::Serializers::Xml
    include ActiveModel::Dirty
    extend ActiveModel::Naming
    extend ActiveModel::Callbacks

    attr_accessor :scope_ldap, :filter_ldap, :basedn_ldap, :passdn_ldap, :list_attributs_type, :list_objectclass, :list_attributs, :list_attributs_rollback	


    define_model_callbacks :create, :update, :save

    def initialize(attributes = {})
      @attributes = attributes
    end

    def read_attribute_for_validation(key)
      @attributes[key]
    end

    def attributes
      @attributes
    end
    
    def new_record?
      new?
    end

    def new?
      connector(_host,_port,_rootdn,_passdn).search(_dn,_scope,_filter)
    end
  end

end