﻿/* Copyright (C) Itseez3D, Inc. - All Rights Reserved
* You may not use this file except in compliance with an authorized license
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* UNLESS REQUIRED BY APPLICABLE LAW OR AGREED BY ITSEEZ3D, INC. IN WRITING, SOFTWARE DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED
* See the License for the specific language governing permissions and limitations under the License.
* Written by Itseez3D, Inc. <support@avatarsdk.com>, April 2017
*/

using System.Collections.Generic;
using UnityEngine;

namespace ItSeez3D.AvatarSdk.Core
{
	public enum PipelineType
	{
		/// <summary>
		/// Standard pipeline (bald head with the neck, supports different haircuts, supports blendshapes).
		/// </summary>
		FACE,

		/// <summary>
		/// Face pipeline with the cartoonish stylization
		/// </summary>
		STYLED_FACE,

		/// <summary>
		/// Pipeline that generates head with hair and shoulders (supports blendshapes)
		/// </summary>
		HEAD
	}

	public static class PipelineTypeExtensions
	{
		public static Dictionary<PipelineType, string> pipelineTypeNameDict = new Dictionary<PipelineType, string>()
		{
			{ PipelineType.FACE, "animated_face"},
			{ PipelineType.STYLED_FACE, "animated_face"},
			{ PipelineType.HEAD, "head_1.1"}
		};

		public static Dictionary<PipelineType, string> pipelineSubtypeNameDict = new Dictionary<PipelineType, string>()
		{
			{ PipelineType.FACE, "base/legacy"},
			{ PipelineType.STYLED_FACE, "indie/legacy_styled"},
			{ PipelineType.HEAD, "base/legacy"}
		};


		private static void SelectHeadPipelineVersion()
		{
			if(AvatarSdkMgr.Settings.UseHeadPipelineV1_2)
			{
				pipelineTypeNameDict[PipelineType.HEAD] = "head_1.2";
			}
			else
			{
				pipelineTypeNameDict[PipelineType.HEAD] = "head_1.1";
			}
		}

		public static string GetPipelineTypeName(this PipelineType pipelineType)
		{
			if(pipelineType == PipelineType.HEAD)
			{
				SelectHeadPipelineVersion();
			}
			return pipelineTypeNameDict[pipelineType];
		}

		public static string GetPipelineSubtypeName(this PipelineType pipelineType)
		{
			return pipelineSubtypeNameDict[pipelineType];
		}

		/// <summary>
		/// Hash function for storing parameters of different pipelines in cache
		/// </summary>
		public static string ParametersSubsetHash(this PipelineType pipelineType, ComputationParametersSubset parametersSubset)
		{
			return string.Format("{0} {1}", parametersSubset.ToString(), pipelineType.ToString());
		}
	}
}
