// ALL RIGHTS RESERVED:
// ====================
// The contents of this file, and associated files in this directory, are 
// Copyright (C) SPT , all rights reserved, 2009.
// All software Source Code, Images, Database-Design and code, Graphics Design 
// and source files, and related content (collectively referred to as SOURCE) are 
// Copyright (c) SPT, 2009, All Rights Reserved.
// http://SerialPortTool.com

// PTZ Controller is a Registered Trademark of SerialPortTool.com.
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Collections;
using System.Xml.Serialization;
using System.Collections.Generic;

namespace PTZController.Logic
{
    public class PresetItem
    {
        /// <summary>
        /// Ctor
        /// </summary>
        public PresetItem()
        {

        }

        /// <summary>
        /// Ctor
        /// </summary>
        public PresetItem(int index)
        {
            this.Index = index;
            this.Name = string.Format("Preset {0:D3}", index);
        }

        public override string ToString()
        {
            return string.Format("{0:D3}. {1}", Index, Name);
        }

        /// <summary>
        /// Preset index
        /// </summary>
        private int m_index;

        [XmlAttribute()]
        public int Index
        {
            get { return m_index; }
            set { m_index = value; }
        }

        /// <summary>
        /// Preset name
        /// </summary>
        private string m_name;

        [XmlAttribute()]
        public string Name
        {
            get { return m_name; }
            set { m_name = value; }
        }
    }

    [XmlRoot("presets")]
    public class PresetItemList
    {
        private ArrayList m_states;

        public PresetItemList()
        {
            m_states = new ArrayList();
        }

        public PresetItemList(int count)
        {
            m_states = new ArrayList();

            for (int i = 1; i < 1 + count; i++)
            {
                m_states.Add(new PresetItem(i));
            }
        }

        public PresetItem this[int index]
        {
            get
            {
                return m_states[index] as PresetItem;
            }
        }

        public int Length
        {
            get { return m_states.Count; }
        }

        [XmlElement("item")]
        public PresetItem[] Items
        {
            get
            {
                PresetItem[] items = new PresetItem[m_states.Count];
                m_states.CopyTo(items);
                return items;
            }
            set
            {
                if (value == null)
                {
                    return;
                }

                PresetItem[] items = (PresetItem[])value;

                m_states.Clear();

                foreach (PresetItem item in items)
                {
                    m_states.Add(item);
                }
            }
        }

        public int Add(PresetItem item)
        {
            return m_states.Add(item);
        }
    }
}
