package fishrungames.bashgid.core;

import java.util.ArrayList;


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)
	{
		MainActivity.getInstance().DownloadImage(recordData.imageUrl, recordData.imageHash);
		
		MainActivity.getInstance().photoDataSource.AddOrReplacePhoto(recordData);
	}
	
	public static void AddExistingPhotoToAlbum(String imageUrl, String albumName)
	{
		if (!MainActivity.getInstance().albumDataSource.IsAlbumAlreadyExist(albumName))
		{
			MainActivity.getInstance().albumDataSource.CreateNewAlbum(new AlbumRecordData(albumName, albumName, "", 1));
		}
		
		MainActivity.getInstance().albumDataSource.AddPhotoToAlbum(imageUrl, albumName);
		
	}
	
	public static void DownloadAndAddPhotoToAlbum(PhotoRecordData recordData, String albumName)
	{
		DownloadAndAddPhoto(recordData);
		
		AddExistingPhotoToAlbum(recordData.imageUrl, albumName);
		
	}
	
	public static void AddNewVideo(VideoRecordData recordData)
	{
		MainActivity.getInstance().DownloadImage(recordData.previewImageUrl, recordData.previewImageHash);
		
		MainActivity.getInstance().videoDataSource.AddOrReplaceVideo(recordData);
	}
	
	
	public static void AddExistingVideoToChannel(String videoUrl, String channelName)
	{
		if (!MainActivity.getInstance().channelDataSource.IsChannelAlreadyExist(channelName))
		{
			MainActivity.getInstance().channelDataSource.CreateNewChannel(new ChannelRecordData(channelName, channelName, "", 1));
		}
		
		MainActivity.getInstance().channelDataSource.AddVideoToChannel(videoUrl, channelName);
		
	}
	
	public static void AddNewVideoToChannel(VideoRecordData recordData, String channelName)
	{
		AddNewVideo(recordData);
		
		AddExistingVideoToChannel(recordData.videoUrl, channelName);
		
	}
	
	public static void AddNewArticle(ArticleRecordData recordData)
	{
		MainActivity.getInstance().articleDataSource.CreateNewArticle(recordData);
	}
	
	
	public static void AddExistingArticleToJournal(String articleName, String journalName)
	{
		if (!MainActivity.getInstance().journalDataSource.IsJournalAlreadyExist(journalName))
		{
			MainActivity.getInstance().journalDataSource.CreateNewJournal(new JournalRecordData(journalName, journalName, "", 1, 0, 0));
		}
		
		MainActivity.getInstance().journalDataSource.AddArticleToJournal(articleName, journalName);
	}
	
	public static void AddNewArticleToJournal(ArticleRecordData recordData, String journalName)
	{
		AddNewArticle(recordData);
		
		AddExistingArticleToJournal(recordData.name, journalName);
		
	}
	

	
	
}
