﻿using System.Collections.Generic;

/*
 * This file is part of lanterna (http://code.google.com/p/lanterna/).
 *
 * lanterna is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright (C) 2010-2017 Martin Berglund
 */
namespace com.googlecode.lanterna.gui2.dialogs
{


	/// <summary>
	/// Dialog builder for the {@code MessageDialog} class, use this to create instances of that class and to customize
	/// them
	/// @author Martin
	/// </summary>
	public class MessageDialogBuilder
	{
		private string title;
		private string text;
		private readonly IList<MessageDialogButton> buttons;
		private readonly ISet<Window.Hint> extraWindowHints;

		/// <summary>
		/// Default constructor
		/// </summary>
		public MessageDialogBuilder()
		{
			this.title = "MessageDialog";
			this.text = "Text";
			this.buttons = new List<MessageDialogButton>();
			this.extraWindowHints = Collections.singleton(Window.Hint.CENTERED);
		}

		/// <summary>
		/// Builds a new {@code MessageDialog} from the properties in the builder </summary>
		/// <returns> Newly build {@code MessageDialog} </returns>
		public virtual MessageDialog build()
		{
			MessageDialog messageDialog = new MessageDialog(title, text, buttons.ToArray());
			messageDialog.Hints = extraWindowHints;
			return messageDialog;
		}

		/// <summary>
		/// Sets the title of the {@code MessageDialog} </summary>
		/// <param name="title"> New title of the message dialog </param>
		/// <returns> Itself </returns>
		public virtual MessageDialogBuilder setTitle(string title)
		{
			if (string.ReferenceEquals(title, null))
			{
				title = "";
			}
			this.title = title;
			return this;
		}

		/// <summary>
		/// Sets the main text of the {@code MessageDialog} </summary>
		/// <param name="text"> Main text of the {@code MessageDialog} </param>
		/// <returns> Itself </returns>
		public virtual MessageDialogBuilder setText(string text)
		{
			if (string.ReferenceEquals(text, null))
			{
				text = "";
			}
			this.text = text;
			return this;
		}

		/// <summary>
		/// Assigns a set of extra window hints that you want the built dialog to have </summary>
		/// <param name="extraWindowHints"> Window hints to assign to the window in addition to the ones the builder will put </param>
		/// <returns> Itself </returns>
		public virtual MessageDialogBuilder setExtraWindowHints(ISet<Window.Hint> extraWindowHints)
		{
			this.extraWindowHints.Clear();
			this.extraWindowHints.addAll(extraWindowHints);
			return this;
		}

		/// <summary>
		/// Adds a button to the dialog </summary>
		/// <param name="button"> Button to add to the dialog </param>
		/// <returns> Itself </returns>
		public virtual MessageDialogBuilder addButton(MessageDialogButton button)
		{
			if (button != null)
			{
				buttons.Add(button);
			}
			return this;
		}
	}

}