//===============================================================================
// Microsoft patterns & practices
// Web Service Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework.Configuration;
using Microsoft.Practices.RecipeFramework;
using System.CodeDom;
using Microsoft.Practices.RecipeFramework.Library.CodeDom.Helpers;
using EnvDTE;
using Microsoft.Practices.SoftwareFactories.ServiceFactory.CommonHelpers;
using Microsoft.Practices.SoftwareFactories.ServiceFactory.Actions.CodeDom.Helpers; 
#endregion

namespace Microsoft.Practices.SoftwareFactories.ServiceFactory.Actions.CodeDom
{
    /// <summary>
    /// Action that transalates an entity into another
    /// </summary>
    public class TranslatorGeneratorAction : ConfigurableAction
    {
        private string classNamespace;
        /// <summary>
        /// Gets or sets the class namespace.
        /// </summary>
        /// <value>The class namespace.</value>
        [Input(Required = true)]
        public string ClassNamespace
        {
            get { return classNamespace; }
            set { classNamespace = value; }
        }

        private Type firstType;
        /// <summary>
        /// Gets or sets the type of the first.
        /// </summary>
        /// <value>The type of the first.</value>
        [Input(Required = true)]
        public Type FirstType
        {
            get { return firstType; }
            set { firstType = value; }
        }

        private Type secondType;
        /// <summary>
        /// Gets or sets the type of the second.
        /// </summary>
        /// <value>The type of the second.</value>
        [Input(Required = true)]
        public Type SecondType
        {
            get { return secondType; }
            set { secondType = value; }
        }

        private LanguageType languageType;
        /// <summary>
        /// Gets or sets the language.
        /// </summary>
        /// <value>The language.</value>
        [Input(Required = true)]
        public LanguageType Language
        {
            get { return languageType; }
            set { languageType = value; }
        }

        private string className;
        /// <summary>
        /// Gets or sets the name of the class.
        /// </summary>
        /// <value>The name of the class.</value>
        [Input(Required = true)]
        public string ClassName
        {
            get { return className; }
            set { className = value; }
        }

        private MappedPropertyList mappedProperties;
        /// <summary>
        /// Gets or sets the property mappings.
        /// </summary>
        /// <value>The property mappings.</value>
        [Input(Required = true)]
        public MappedPropertyList PropertyMappings
        {
            get { return mappedProperties; }
            set { mappedProperties = value; }
        }

        private CodeCompileUnit translatorCompilationUnit;
        /// <summary>
        /// Gets or sets the translator compile unit.
        /// </summary>
        /// <value>The translator compile unit.</value>
        [Output]
        public CodeCompileUnit TranslatorCompileUnit
        {
            get { return translatorCompilationUnit; }
            set { translatorCompilationUnit = value; }
        }

        /// <summary>
        /// Gets the name of the translator class file.
        /// </summary>
        /// <value>The name of the translator class file.</value>
        [Output]
        public string TranslatorClassFileName
        {
            get { return ClassName + (languageType == LanguageType.cs ? ".cs" : ".vb"); }
        }

        /// <summary>
        /// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Execute"/>.
        /// </summary>
        public override void Execute()
        {
            TranslatorGenerator generator = new TranslatorGenerator(classNamespace);
            generator.Map(firstType, secondType, className, mappedProperties);
            translatorCompilationUnit = generator.CompileUnit;
        }

        /// <summary>
        /// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Undo"/>.
        /// </summary>
        public override void Undo()
        {
            //Not Implemented
        }
    }
}
