using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;

// TODO: replace these with the processor input and output types.
using TInput = System.String;
using TOutput = System.String;

namespace ReplacementPipeline
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to apply custom processing to content data, converting an object of
    /// type TInput to TOutput. The input and output types may be the same if
    /// the processor wishes to alter data without changing its type.
    ///
    /// This should be part of a Content Pipeline Extension Library project.
    ///
    /// TODO: change the ContentProcessor attribute to specify the correct
    /// display name for this processor.
    /// </summary>
    [ContentProcessor]
    public class ReplacementFX : ModelProcessor
    {
        protected override MaterialContent ConvertMaterial(
            MaterialContent material, ContentProcessorContext context )
        {
            return context.Convert<MaterialContent, MaterialContent>(material,"MaterialCustomEffectProcessor");
        }
    }

    [ContentProcessor]
    public class MaterialCustomEffectProcessor : MaterialProcessor
    {
        public override MaterialContent Process( MaterialContent input, ContentProcessorContext context )
        {
            EffectMaterialContent myMaterial = new EffectMaterialContent();

            myMaterial.Effect = new ExternalReference<EffectContent>( "shaders/ReplaceColor.fx" );

            foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture
                in input.Textures)
            {
                myMaterial.Textures.Add( texture.Key, texture.Value );
            }

            return context.Convert<MaterialContent, MaterialContent>(myMaterial,"MaterialProcessor");
        }
    }
}