using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Drawing;
using ImageBlockz.Api;
using ImageBlockz.Core;

namespace ImageBlockz.Operations.InOut
{
    public class SaveFile : AbstractOperation
    {
        public static readonly string OperationName = typeof(SaveFile).FullName;

        public SaveFile() : base(OperationType.Output)
        {
        
        }

        public SaveFile(string filename) : this()
        {
            Filename = filename;
        }

        public string Filename
        {
            get;
            set;
        }

        public override Bitmap Do(Bitmap bitmap)
        {
            SaveToJpg.SaveJpg(bitmap, Filename, 100);

            return bitmap;
        }

        public override XmlNode ToXml(XmlDocument xmlDoc)
        {
            XmlElement savefile = xmlDoc.CreateElement(OperationName);
            XmlElement filename = xmlDoc.CreateElement("filename");

            filename.AppendChild(xmlDoc.CreateTextNode(Filename));
            savefile.AppendChild(filename);

            return savefile;
        }

        public override void FromXml(XmlNode node)
        {
            Filename = node["filename"].FirstChild.Value;
        }

        public override string GetFormattedName()
        {
            return "Save File";
        }

        public override string GetInfo()
        {
            return "Filename: " + Filename;
        }
    }
}
