namespace uniflash.resets {

	'use strict';

	angular.module('uniflash').service('ufResets', resets);
	resets.$inject = ['ufSession', 'ufContext'];

	interface ResetInfo {
		resetAfterLoad: boolean;
		selectedResetOption: string;
		//availableResetOptions: { [key: string]: boolean }; // map of reset name vs isEnabled currently flags
		availableResetOptions: string[]; // list of reset names, simple impl for now
	}

	interface Core {
		name: string;
		reset: ResetInfo;
	}

	function resets(ufSession: uniflash.session.SessionService,
		ufContext: uniflash.Context, ufIsBinary, ticFileFactory: ti_common.file.IFileFactory, ufProgramProviders) {

		let cores: { [name: string]: Core } = {};

		ufSession.registerSessionDataProvider('resets', {
			onSessionLoad: () => {

				cores = {}; // reset data
				// init cores
				_.each(ufSession.queryConfig().cores, (coreInfo) => {
					cores[coreInfo.name] = {
						name: coreInfo.name,
						reset: {
							resetAfterLoad: false,
							selectedResetOption: undefined,
							availableResetOptions: []
						} as ResetInfo
					};
				});
			},
			getSessionData: () => {}
		});

		function getCoreData() {
			return cores[ufContext.getCurrentCore().name];
		}

		function getAllGUICoresData() {
			return _.map(ufSession.queryConfig().cores, (coreInfo) => {
				return cores[coreInfo.name];
			});
		}

		function getReset(): ResetInfo{
			return getCoreData().reset;
		}

		function getResetOnCore(coreName): ResetInfo {
			if (coreName && cores[coreName]) {
				return cores[coreName].reset;
			} else {
				return undefined;
			}
		}

		return {
			getReset: getReset,
			getAllGUICoresData: getAllGUICoresData,
			getResetOnCore: getResetOnCore,
		};
	}

}