/*
 *  Copyright 2023 Anyware Services
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * This class is the representation of a temporary user.
 * @private
 */
Ext.define(
	"Ametys.plugins.web.tempusers.TempUser", 
	{
		config: {
			/**
			 * @cfg {String} email The email of this temporary user
			 */
			/**
			 * @method getEmail Get the #cfg-email
			 * @return {String} The email
			 */
			/** @ignore */
			email: null,
			/**
			 * @cfg {String} siteName The site name of this temporary user
			 */
			/**
			 * @method getSiteName Get the #cfg-siteName
			 * @return {String} The site name
			 */
			/** @ignore */
			siteName: null,
            /**
             * @cfg {String} population The id of population of this temporary user
             */
            /**
             * @method getPopulation Get the #cfg-population
             * @return {String} The population
             */
            /** @ignore */
            population: null,
            /**
             * @cfg {String} userDirectory The id of user directory of this temporary user
             */
            /**
             * @method getUserDirectory Get the #cfg-userDirectory
             * @return {String} The user directory
             */
            /** @ignore */
            userDirectory: null,
            /**
             * @cfg {String} origin The signup request origin
             */
            /**
             * @method getOrigin Get the #cfg-origin
             * @return {boolean} True if the signup request origin
             */
            /** @ignore */
            origin: null,
			/**
			 * @cfg {boolean} expired True if the signup request is expired
			 */
			/**
			 * @method getExpired Get the #cfg-expired
			 * @return {boolean} True if the signup request is expired
			 */
			/** @ignore */
			expired: false,
			/**
			 * @cfg {boolean} canHandle True if this temporay user is in write-access for the current user
			 */
            /**
             * @method getCanHandle Get the #cfg-canHandle
             * @return {boolean} True if the temporay user is in write-access
             */
            /** @ignore */
            canHandle: false,
            /**
             * @cfg {Object} subscriptionDate The subscription date
             */
            /**
             * @method getSubscriptionDate Get the #cfg-subscriptionDate
             * @return {String} The subscription date
             */
            /** @ignore */
            subscriptionDate: null
		},
		
		
		/**
		 * Creates a temporary user instance
		 * @param {Object} config See configuration doc.
		 */
		constructor: function (config)
		{
			this.initConfig(config);
			
			this.messageTarget = config.messageTarget || Ametys.message.MessageTarget.TEMP_USER;
		},
		
		/**
		 * Get the temporary user's properties
		 * @return {Object} The temporary user's properties
		 */
		getProperties: function (initialProperty)
		{
			initialProperty = initialProperty || {};
			
			return Ext.apply ({
					email: this._email,
					siteName: this._siteName,
                    population: this._population,
                    userDirectory: this._userDirectory,
					canHandle: this._canHandle,
                    expired: this._expired,
                    origin: this._origin,
                    subscriptionDate: this._subscriptionDate
				}, initialProperty
			);
		},
        
        /**
         * Update the temporary user's properties
         * @param {Object} properties The temporary users's properties. Only subscription date and expired are supported
         */
        setProperties: function (properties)
        {
            this.setConfig('subscriptionDate', properties.subscriptionDate);
            this.setConfig('expired', properties.expired);
        }
	}
);