using System;
using System.Collections.Generic;
using System.Text;

namespace pcmp
{
    public class BalloonMessageManager
    {
        // ----------------------------------------------------------
        // フィールド
        // ----------------------------------------------------------
        private Queue<BalloonMessageItem> queue;

        // ----------------------------------------------------------
        // プロパティ
        // ----------------------------------------------------------
        public Queue<BalloonMessageItem> Queue
        {
            get { return queue; }
            set { queue = value; }
        }

        // ----------------------------------------------------------
        // メソッド
        // ----------------------------------------------------------
        /// <summary>
        /// キューにチャンネルを追加する
        /// </summary>
        /// <param name="channels">追加するChannelのリスト</param>
        public void AddChannels(List<Channel> channels)
        {
            if (channels == null) throw new ArgumentNullException();
            BalloonMessageItem nitem;
            foreach (Channel item in channels)
            {
                nitem = new BalloonMessageItem();
                nitem.Text = item.ChannelName + "\n" + item.Detail.Substring(0, 30);
                nitem.Sound = item.Sound;
                nitem.Channel = item;
                queue.Enqueue(nitem);
            }
        }

        /// <summary>
        /// キューにチャンネルを追加する
        /// </summary>
        /// <param name="item">追加するChannel</param>
        /// <param name="title">追加するアイテムのタイトル</param>
        public void AddChannel(Channel item, string title)
        {
            if (item == null) throw new ArgumentNullException();
            BalloonMessageItem nitem = new BalloonMessageItem();
            nitem.Title = title;
            string detail;
            if (item.Detail.Length > 30)
                detail = item.Detail.Substring(0, 30);
            else
                detail = item.Detail;
            nitem.Text = item.ChannelName + "(" + item.Status + ")\n　" + detail;
            nitem.Sound = item.Sound;
            nitem.Channel = item;
            queue.Enqueue(nitem);
        }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        public BalloonMessageManager()
        {
            queue = new Queue<BalloonMessageItem>();
        }
    }

    public class BalloonMessageItem : ICloneable
    {
        // ----------------------------------------------------------
        // フィールド
        // ----------------------------------------------------------
        public string Text = string.Empty;
        public string Title = string.Empty;
        public string Sound = string.Empty;
        public Channel Channel = null;

        #region ICloneable メンバ

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        #endregion
    }
}
