/*
 * Created on Jun 30, 2008 (C) Copyright TANDBERG Television Ltd.
 */

package com.tandbergtv.watchpoint.pmm.util;

import java.io.File;
import java.util.ResourceBundle;

/**
 * @author Vijay Silva
 */
public final class PathProperties {

	/* The name of the Resource Bundle */
	private static final String BUNDLE_NAME = "template-actions.path";

	/* Load the Resource Bundle */
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

	/**
	 * The Property Name containing the top-level folder path containing all the Provider specific
	 * content.
	 */
	public static final String CONTENT_PATH = "contentPath";

	/**
	 * The Property Name containing the top-level folder path containing all the Provider specific
	 * content that is unmapped (to titles).
	 */
	public static final String UNMAPPED_CONTENT_PATH = "unmappedContentPath";

	/**
	 * Property name containing the folder path for saving files temporarily.
	 * e.g. provider id is not yet known at this stage. So save the file here
	 * Later on when provider id is available, the file will be moved to the 
	 * expected destination path.
	 */
	public static final String TEMP_CONTENT_PATH = "tempContentPath"; 
	
	// ==============================================================
	// ====================== ORIGINAL CONTENT PATHS
	// ==============================================================

	/**
	 * The Property Name containing the relative folder path for the original content for a
	 * provider. The path is relative to folder: &lt;ContentPath&gt;/&lt;ProviderId&gt;
	 */
	public static final String ORIGINAL_CONTENT_PATH = "provider.original";

	/**
	 * Folder Path for original content of the Title Assets (relative to Provider content folder)
	 */
	public static final String ORIGINAL_ASSET_PATH = "provider.original.asset";

	/**
	 * Folder Path for original content of the Planners (relative to Provider content folder)
	 */
	public static final String ORIGINAL_PLANNER_PATH = "provider.original.planner";

	/**
	 * Folder Path for original content of the Pitch Schedules (relative to Provider content folder)
	 */
	public static final String ORIGINAL_PITCH_SCHEDULE_PATH = "provider.original.pitchSchedule";

	/**
	 * Folder Path for original content of the Program Lists (relative to Provider content folder)
	 */
	public static final String ORIGINAL_PROGRAM_LIST_PATH = "provider.original.programList";

	// ==============================================================
	// ====================== INGESTED CONTENT PATHS
	// ==============================================================

	/**
	 * The Property Name containing the relative folder path for the ingested content for a
	 * provider. The path is relative to folder: &lt;ContentPath&gt;/&lt;ProviderId&gt;
	 */
	public static final String INGEST_CONTENT_PATH = "provider.ingest";

	/**
	 * Folder Path for ingested content for Title Assets (relative to Provider content folder)
	 */
	public static final String INGEST_ASSET_PATH = "provider.ingest.asset";

	/**
	 * Folder Path for ingested content of the Planners (relative to Provider content folder)
	 */
	public static final String INGEST_PLANNER_PATH = "provider.ingest.planner";

	/**
	 * Folder Path for ingested content of the Pitch Schedules (relative to Provider content folder)
	 */
	public static final String INGEST_PITCH_SCHEDULE_PATH = "provider.ingest.pitchSchedule";

	/**
	 * Folder Path for ingested content of the Program Lists (relative to Provider content folder)
	 */
	public static final String INGEST_PROGRAM_LIST_PATH = "provider.original.programList";

	// ==============================================================
	// ====================== PROCESSED CONTENT PATHS
	// ==============================================================

	/**
	 * The Property Name containing the relative folder path for the processed content for a
	 * provider. The path is relative to folder: &lt;ContentPath&gt;/&lt;ProviderId&gt;
	 */
	public static final String PROCESSED_CONTENT_PATH = "provider.processed";

	/**
	 * Folder Path for the Processed Title Content (relative to the Provider content folder)
	 */
	public static final String PROCESSED_TITLES_PATH = "provider.processed.title";

	/**
	 * Folder Path for the Processed Planner Content (relative to the Provider content folder)
	 */
	public static final String PROCESSED_PLANNER_PATH = "provider.processed.planner";

	/**
	 * Folder Path for the Processed Program List Content (relative to the Provider content folder)
	 */
	public static final String PROCESSED_PROGRAM_LIST_PATH = "provider.processed.programList";

	/**
	 * Folder Path for the Processed Pitch Schedules (relative to the Provider/Service content
	 * folder)
	 */
	public static final String PROCESSED_PITCH_SCHEDULE_PATH = "provider.processed.pitchSchedule";

	// ==============================================================
	// ====================== PROCESSED TITLE PATHS FOR EACH TITLE
	// ==============================================================

	/**
	 * Path to the processed package relative to the title folder present in the processed titles
	 * folder in the provider folder. The path is relative to:
	 * &lt;ContentPath&gt;/&lt;ProviderId&gt;/&lt;PROCESSED_TITLES_PATH&gt;/&lt;TitleId&gt;
	 */
	public static final String PROCESSED_TITLE_PACKAGE = "title.processed.package";

	/**
	 * Path to the processed assets relative to the title folder present in the processed titles
	 * folder in the provider folder. The path is relative to:
	 * &lt;ContentPath&gt;/&lt;ProviderId&gt;/&lt;PROCESSED_TITLES_PATH&gt;/&lt;TitleId&gt;
	 */
	public static final String PROCESSED_TITLE_ASSET = "title.processed.asset";

	/* Cannot instantiate this class */
	private PathProperties() {
	}

	/**
	 * Gets the value of a property given the format key and property name
	 * 
	 * @param formatKey The Format Key
	 * @param propertyName The Property Name
	 * @return the value
	 */
	public static String getProperty(String propertyName) {
		return RESOURCE_BUNDLE.getString(propertyName);
	}

	/**
	 * Get the Content Path for the Provider given the Provider ID
	 * 
	 * @param providerId The Provider Id
	 * @return The folder path to the content for the provider Id
	 */
	public static String getProviderPath(String providerId) {
		return getProviderFolder(providerId).getAbsolutePath();
	}

	/**
	 * Get the Absolute Path for the content specific folder for the Provider given the provider ID
	 * and the path property key
	 * 
	 * @param providerId Provider Id
	 * @param key The Path key for the provider content folder
	 * @return The Absolute Path for the given key
	 */
	public static String getProviderPath(String providerId, String key) {
		File providerFolder = getProviderFolder(providerId);
		String relativePath = getProperty(key);

		return new File(providerFolder, relativePath).getAbsolutePath();
	}

	/**
	 * Get the Absolute Path for the content folder for the Title for a specific Provider given the
	 * provider ID, the Title Id and the path property key
	 * 
	 * @param providerId The Provider Id
	 * @param titleId The Title Id
	 * @return The Absolute Path for the given key
	 */
	public static String getTitlePath(String providerId, String titleId) {
		return getTitleFolder(providerId, titleId).getAbsolutePath();
	}

	/**
	 * Get the Absolute Path for the content folder for the Title for a specific Provider given the
	 * provider ID, the Title Id and the path property key
	 * 
	 * @param providerId The Provider Id
	 * @param titleId The Title Id
	 * @param key The Path key for the title content folder for the provider
	 * @return The Absolute Path for the given key
	 */
	public static String getTitlePath(String providerId, String titleId, String key) {
		File titleFolder = getTitleFolder(providerId, titleId);
		String relativePath = getProperty(key);

		return new File(titleFolder, relativePath).getAbsolutePath();
	}

	/**
	 * Get the Unmapped Content Path for the Provider given the Provider ID
	 * 
	 * @param providerId The Provider Id
	 * @return The folder to the unmapped content for the provider Id
	 */
	public static final File getUnmappedProviderFolder(String providerId) {
		String unmappedContentPath = getProperty(UNMAPPED_CONTENT_PATH);
		return new File(unmappedContentPath, providerId);
	}
	
	/*
	 * Get the File object for the content folder for the Provider
	 */
	private static File getProviderFolder(String providerId) {
		String contentPath = getProperty(CONTENT_PATH);
		return new File(contentPath, providerId);
	}

	/*
	 * Get the File object for the title folder for the Provider's processed title content
	 */
	private static File getTitleFolder(String providerId, String titleId) {
		String titlesPath = getProviderPath(providerId, PROCESSED_TITLES_PATH);
		return new File(titlesPath, titleId);
	}

}
