/*
 *  Copyright 2018 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 factory creates Ametys.message.MessageTarget for content types.
 */
Ext.define("Ametys.plugins.contenttypeseditor.ContentTypeMessageTargetFactory",
    {
        extend: "Ametys.message.MessageTargetFactory",

        /**
         * Create the targets for a message
         * @param {Object} parameters The parameters needed by the factory to create the message. Can not be null. Handled elements are :
         * @param {String} parameters.id The tool identifier.
         * @param {Boolean} [parameters.isNew] Is the content type known by the server? (or local only)
         * @param {Boolean} [parameters.editor] Is the content type open in the content type editor and focus ?
         * @param {Function} callback The callback function called when the targets are created. Parameters are
         * @param {Ametys.message.MessageTarget[]} callback.targets The targets created. Cannot be null.
         * @param {String} targetId The id of target
         */
        createTargets: function(parameters, callback, targetId)
        {
            var target = Ext.create("Ametys.message.MessageTarget", {
                id: targetId,
                parameters: {
                    id: parameters.id,
                    isNew: parameters.isNew ? true : false,
                    editor: parameters.editor ? true : false
                }
            });     
            callback([target]);
        }
    }
);

Ext.define('Ametys.plugins.contenttypeseditor.ContentTypeMessageTarget', {
    override: 'Ametys.message.MessageTarget',
    
    statics:
    {
        /**
         * @readonly
         * @member Ametys.message.MessageTarget
         * The target is representing a content type. To create such a target see Ametys.plugins.contenttypeseditor.ContentTypeMessageTargetFactory#createTargets
         * @property {String} CONTENT_TYPE The target id is a content type. Parameters are:
         * @property {String} CONTENT_TYPE.id The content type's identifier
         * @property {Boolean} [CONTENT_TYPE.isNew=false] Is the content type known by the server? (or local only)
         */
        CONTENT_TYPE: 'content-type',
        
        /**
         * @readonly
         * @member Ametys.message.MessageTarget
         * The target is representing a metadata of a content type.
         * @property {String} METADATA_CONTENT_TYPE The target id is a metadata of content type. Parameters are:
         * @property {String} METADATA_CONTENT_TYPE The type of metadata
         */
        METADATA_CONTENT_TYPE: 'metadata-content-type',
        
         /**
         * @readonly
         * @member Ametys.message.MessageTarget
         * The target is representing a metadata set of a content type.
         * @property {String} METADATA_SET_CONTENT_TYPE The target id is a metadata set of content type.
         */
        METADATA_SET_CONTENT_TYPE: 'metadata-set-content-type'
    }

});