package fishrungames.bashgid.core;

import java.util.ArrayList;


import fishrungames.bashgid.BashgidApplication;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ChannelManager.ChannelRecordData;
import fishrungames.bashgid.core.JournalManager.JournalRecordData;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
import fishrungames.bashgid.core.VideoManager.VideoRecordData;


public class AlbumManager
{
	
	public static class AlbumRecordData
	{
		public String name;
		public String title;
		public String description;
		public int hidden;
		
		public AlbumRecordData(String name, String title, String description, int hidden)
		{
			this.name = name;
			this.title = title;
			this.description = description;
			this.hidden = hidden;
		}
		
		public AlbumRecordData(AlbumRecordData copyFrom)
		{
			this.name = copyFrom.name;
			this.title = copyFrom.title;
			this.description = copyFrom.description;
			this.hidden = copyFrom.hidden;
		}
	}
	
	public static class AlbumFullData extends AlbumRecordData
	{
		public ArrayList<PhotoManager.PhotoRecordData> photoRecordArr;
		
		public AlbumFullData(AlbumRecordData recordData)
		{
			super(recordData);
			this.photoRecordArr = new ArrayList<PhotoManager.PhotoRecordData>();
		}
	}
	
	public static class AlbumShortData extends AlbumRecordData
	{
		public String firstImageUrl;
		
		public int photoCount;
		
		public AlbumShortData(AlbumRecordData recordData)
		{
			super(recordData);
			firstImageUrl = "";
			photoCount = 0;
		}
	}
	
	public static AlbumFullData CreateEmptyAlbum()
	{
		AlbumFullData result = new AlbumFullData(new AlbumRecordData("", "", "", 1));
		
		return result;
	}
	
	
	public static void DownloadAndAddPhoto(PhotoRecordData recordData)
	{
		BashgidApplication.DownloadImage(recordData.imageUrl, recordData.imageHash);
		
		BashgidApplication.photoDataSource.AddOrReplacePhoto(recordData);
	}
	
	public static void AddExistingPhotoToAlbum(String imageUrl, String albumName)
	{
		if (!BashgidApplication.albumDataSource.IsAlbumAlreadyExist(albumName))
		{
			BashgidApplication.albumDataSource.CreateNewAlbum(new AlbumRecordData(albumName, albumName, "", 1));
		}
		
		BashgidApplication.albumDataSource.AddPhotoToAlbum(imageUrl, albumName);
		
	}
	
	public static void DownloadAndAddPhotoToAlbum(PhotoRecordData recordData, String albumName)
	{
		DownloadAndAddPhoto(recordData);
		
		AddExistingPhotoToAlbum(recordData.imageUrl, albumName);
		
	}
	
	public static void AddNewVideo(VideoRecordData recordData)
	{
		BashgidApplication.DownloadImage(recordData.previewImageUrl, recordData.previewImageHash);
		
		BashgidApplication.videoDataSource.AddOrReplaceVideo(recordData);
	}
	
	
	public static void AddExistingVideoToChannel(String videoUrl, String channelName)
	{
		if (!BashgidApplication.channelDataSource.IsChannelAlreadyExist(channelName))
		{
			BashgidApplication.channelDataSource.CreateNewChannel(new ChannelRecordData(channelName, channelName, "", 1));
		}
		
		BashgidApplication.channelDataSource.AddVideoToChannel(videoUrl, channelName);
		
	}
	
	public static void AddNewVideoToChannel(VideoRecordData recordData, String channelName)
	{
		AddNewVideo(recordData);
		
		AddExistingVideoToChannel(recordData.videoUrl, channelName);
		
	}
	
	public static void AddNewArticle(ArticleRecordData recordData)
	{
		BashgidApplication.articleDataSource.CreateNewArticle(recordData);
	}
	
	
	public static void AddExistingArticleToJournal(String articleName, String journalName)
	{
		if (!BashgidApplication.journalDataSource.IsJournalAlreadyExist(journalName))
		{
			BashgidApplication.journalDataSource.CreateNewJournal(new JournalRecordData(journalName, journalName, "", 1, 0, 0));
		}
		
		BashgidApplication.journalDataSource.AddArticleToJournal(articleName, journalName);
	}
	
	public static void AddNewArticleToJournal(ArticleRecordData recordData, String journalName)
	{
		AddNewArticle(recordData);
		
		AddExistingArticleToJournal(recordData.name, journalName);
		
	}
	

	
	
}
