using OKHOSTING.Broadcasting;
using OKHOSTING.ORM.UI;

namespace OKHOSTING.UDG.Radio.Admin.UI.Web
{ 
	public class IndexController : OKHOSTING.UI.Controller
	{
		/// <summary>
		/// Setups the database
		/// </summary>
		public override void Start()
		{
			base.Start();
			Finish();

			var comments = new ORM.Operations.Select<UserComment>();
			comments.AddMembers
			(
				c=> c.Id,
				c=> c.UserAlias,
				c => c.Comment,
				c => c.Date,
				c=> c.Position,
				c => c.Medium.Name,
				c=> c.Transmission.Content.Name
			);

			comments.Limit = new ORM.Operations.SelectLimit(0, 20);
			comments.OrderBy.Add(new ORM.Operations.OrderBy(comments.DataType["Date"], Data.SortDirection.Descending));

			App.Current.Home = comments;
			App.Current.Menu.Add(comments);
			App.Current.DefaultSelects.Add(comments);

			var conections = new ORM.Operations.Select<UserConnection>();
			conections.AddMembers
			(
				c => c.Id,
				c => c.UserAlias,
				c => c.Value,
				c => c.Date,
				c => c.Position,
				c => c.Medium.Name,
				c => c.Transmission.Content.Name
			);

			conections.Limit = new ORM.Operations.SelectLimit(0, 20);
			conections.OrderBy.Add(new ORM.Operations.OrderBy(comments.DataType["Date"], Data.SortDirection.Descending));

			App.Current.Menu.Add(conections);
			App.Current.DefaultSelects.Add(conections);

			var ratings = new ORM.Operations.Select<UserRating>();
			ratings.AddMembers
			(
				c => c.Id,
				c => c.UserAlias,
				c => c.Value,
				c => c.Date,
				c => c.Position,
				c => c.Medium.Name,
				c => c.Transmission.Content.Name
			);

			ratings.Limit = new ORM.Operations.SelectLimit(0, 20);
			ratings.OrderBy.Add(new ORM.Operations.OrderBy(comments.DataType["Date"], Data.SortDirection.Descending));

			App.Current.Menu.Add(ratings);
			App.Current.DefaultSelects.Add(ratings);

			var stations = new ORM.Operations.Select<Station>();
			stations.AddMembers
			(
				c => c.Id,
				c => c.Name,
				c => c.HomeUri,
				c => c.Virtual
			);

			stations.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(stations);
			App.Current.DefaultSelects.Add(stations);

			var tvChannels = new ORM.Operations.Select<Broadcasting.TV.Channel>();
			tvChannels.AddMembers
			(
				c => c.Id,
				c => c.Name,
				c => c.HomeUri
			);

			tvChannels.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(tvChannels);
			App.Current.DefaultSelects.Add(tvChannels);

			var podcast = new ORM.Operations.Select<Broadcasting.Web.PodcastChannel>();
			podcast.AddMembers
			(
				c => c.Id,
				c => c.Name,
				c => c.HomeUri
			);

			podcast.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(podcast);
			App.Current.DefaultSelects.Add(podcast);

			var shows = new ORM.Operations.Select<Show>();
			shows.AddMembers
			(
				c => c.Id,
				c => c.Name,
				c => c.Description
			);

			shows.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(shows);
			App.Current.DefaultSelects.Add(shows);

			var content = new ORM.Operations.Select<Content>();
			content.AddMembers
			(
				c => c.Id,
				c => c.Name,
				c => c.Description,
				c => c.Lenght,
				c => c.Created
			);

			content.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(content);
			App.Current.DefaultSelects.Add(content);

			var episodes = new ORM.Operations.Select<Episode>();
			episodes.AddMembers
			(
				c => c.Id,
				c => c.Name,
				c => c.Description,
				c => c.Show.Name,
				c => c.Lenght,
				c => c.Description,
				c => c.Created
			);

			episodes.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(episodes);
			App.Current.DefaultSelects.Add(episodes);

			var transmissions = new ORM.Operations.Select<Transmission>();
			transmissions.AddMembers
			(
				c => c.Id,
				c => c.Content.Name,
				c => c.Medium.Name,
				c => c.Date,
				c => c.Lenght
			);

			transmissions.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(transmissions);
			App.Current.DefaultSelects.Add(transmissions);

			var schedules = new ORM.Operations.Select<WeeklySchedule>();
			schedules.AddMembers
			(
				c => c.Id,
				c => c.Show.Name,
				c => c.Medium.Name,
				c => c.DayOfWeek,
				c => c.StartTime,
				c => c.Lenght
			);

			schedules.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(schedules);
			App.Current.DefaultSelects.Add(schedules);

			var users = new ORM.Operations.Select<Authentication.UI.User>();
			users.AddMembers
			(
				c => c.Id,
				c => c.UserName,
				c => c.Disabled
			);

			users.Limit = new ORM.Operations.SelectLimit(0, 20);

			App.Current.Menu.Add(users);
			App.Current.DefaultSelects.Add(users);

			new Authentication.UI.LoginController(new SelectController(comments)).Start();
		}
	}
}