/*
 *  Copyright 2017 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 query.
 * @private
 */
Ext.define(
	"Ametys.plugins.queriesdirectory.Query", 
	{
		config: {
			/**
			 * @cfg {String} id The unique id of the query
			 */
			/**
			 * @method getId Get the #cfg-id
			 * @return {String} The id
			 */
			/** @ignore */
			id: null,
			/**
			 * @cfg {String} title The title of the query
			 */
			/**
			 * @method getTitle Get the #cfg-title
			 * @return {String} The title
			 */
			/** @ignore */
			title: null,
            /**
             * @cfg {String} description The description of the query
             */
            /**
             * @method getDescription Get the #cfg-description
             * @return {String} The description
             */
            /** @ignore */
            description: null,
            /**
             * @cfg {String} documentation The documentation of the query
             */
            /**
             * @method getDocumentation Get the #cfg-documentation
             * @return {String} The documentation
             */
            /** @ignore */
            documentation: null,
			/**
			 * @cfg {boolean} canRead True if the query is in read-access for the current user
			 */
			/**
			 * @method getCanRead Get the #cfg-canRead
			 * @return {boolean} True if the query is in read-access
			 */
			/** @ignore */
			canRead: false,
			/**
			 * @cfg {boolean} canWrite True if the query is in write-access for the current user
			 */
            /**
             * @method getCanWrite Get the #cfg-canWrite
             * @return {boolean} True if the query is in write-access
             */
            /** @ignore */
            canWrite: false,
            /**
             * @cfg {boolean} canDelete True if the query can be deleted for the current user
             */
            /**
             * @method getCanDelete Get the #cfg-canDelete
             * @return {boolean} True if the query is removeable
             */
            /** @ignore */
            canDelete: false,
            /**
             * @method getCanAssignRights Get the #cfg-canAssignRights
             * @return {boolean} True if the user can edit query rights
             */
            /** @ignore */
            canAssignRights: false,
            /**
             * @cfg {Object} author The query owner
             */
            /**
             * @method getAuthor Get the #cfg-author
             * @return {String} The query owner
             */
            /** @ignore */
            author: null,
            /**
             * @cfg {Object} contributor The query last contributor
             */
            /**
             * @method getContributor Get the #cfg-contributor
             * @return {String} The query last contributor
             */
            /** @ignore */
            contributor: null,
            /**
             * @cfg {Object} lastModificationDate The query last modification date
             */
            /**
             * @method getLastModificationDate Get the #cfg-lastModificationDate
             * @return {String} The query last modification date
             */
            /** @ignore */
            lastModificationDate: null,
            /**
             * @cfg {Object} creationDate The query creation date
             */
            /**
             * @method getCreationDate Get the #cfg-creationDate
             * @return {String} The query creation date
             */
            /** @ignore */
            creationDate: null,
            /**
             * @method getType Get the #cfg-type
             * @return {String} The type of query
             */
            /** @ignore */
            type: null,
            /**
             * @method getContent Get the #cfg-content
             * @return {String} The description of query
             */
            /** @ignore */
            content: null
		},
		
		
		/**
		 * Creates a content instance
		 * @param {Object} config See configuration doc.
		 */
		constructor: function (config)
		{
			this.initConfig(config);
			
			this.messageTarget = config.messageTarget || Ametys.message.MessageTarget.QUERY;
		},
		
		/**
		 * Get the query's properties
		 * @return {Object} The query's properties
		 */
		getProperties: function (initialProperty)
		{
			initialProperty = initialProperty || {};
			
			return Ext.apply ({
					id: this._id,
					title: this._title,
                    description: this._description,
                    documentation: this._documentation,
					canRead: this._canRead,
					canWrite: this._canWrite,
                    canDelete: this._canDelete,
                    canAssignRights: this._canAssignRights,
                    author: this._author,
                    contributor: this._contributor,
                    creationDate: this._creationDate,
                    lastModificationDate: this._lastModificationDate,
                    fullPath: this.fullPath,
                    type: this._type
				}, initialProperty
			);
		},
        
        /**
         * Update the query's properties
         * @param {Object} properties The query's properties. Only title, description are supported
         */
        setProperties: function (properties)
        {
            this.setConfig('title', properties.title);
            this.setConfig('description', properties.description);
            this.setConfig('documentation', properties.documentation);
        }
	}
);