<?php

/**
 * User request
 *
 * LICENSE: This Software is the property of Lifestyle Webconsulting GmbH (Aschaffenburg, Germany)
 * and is protected by copyright law - it is NOT Freeware.
 *
 * Any unauthorized use of this software without a valid license
 * is a violation of the license agreement and will be prosecuted by
 * civil and criminal law.
 *
 * @copyright  2014 Lifestyle Webconsulting GmbH
 * @version    $Id:$
 * @link       http://www.life-style.de
 */

namespace Sso\WebserviceBundle\Model\Request\User;

/**
 * User request add user
 */
class Add extends Base
{
    /**
     * Init user model
     * @param \SimpleXMLElement $simpleXML
     */
    public function init($simpleXML)
    {
        parent::init($simpleXML);
        $this->setUserModel($this->_factoryUser($simpleXML->Value->UserType->children()));
    }

    /**
     * Build user object
     * @param \DOMElement $xml
     * @return \Sso\WebserviceBundle\Entity\Webservice\Type\User
     */
    protected function _factoryUser($xml)
    {
        // Validate for add
        return $this->typeF->user($xml, array('User_Add'));
    }

    /**
     * Returns a list of allowed field names in xml
     * @return string
     */
    protected function _xmlAllowedElements()
    {
        return '<Value required="true">'
                . '<UserType required="true">'
                . '<Email></Email>'
                . '<Username required="true"></Username>'
                . '<Firstname required="true"></Firstname>'
                . '<Lastname required="true"></Lastname>'
                . '<Password required="true"></Password>'
                . '<Active required="true"></Active>'
                . '<AuthId></AuthId>'
                . '<LdapSearchAttributes></LdapSearchAttributes>'
                . '<LdapSearchValue></LdapSearchValue>'
                . '<MfaEnabled></MfaEnabled>'
                . '</UserType>'
                . '</Value>';
    }
}
