/* 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>, October 2026
*/

namespace AvatarSDKMove
{
	public class ServerEndpoints
	{
		public string name;
		public string apiUrl;
		public string metapersonApiUrl;
		public string metapersonCreatorUrl;
		public string clientId;
		public string clientSecret;
	}

	public static class AvatarSDKMoveServer
	{
		private const string PrimaryServerName = "Primary";

		private static ServerEndpoints overrideServer;

		public static bool IsOverridden { get { return overrideServer != null; } }

		public static string Name { get { return overrideServer == null ? PrimaryServerName : overrideServer.name; } }

		public static string ApiUrl { get { return overrideServer == null ? AvatarSDKMoveSettings.ApiUrl : overrideServer.apiUrl; } }

		public static string MetaPersonApiUrl { get { return overrideServer == null ? AvatarSDKMoveSettings.MetaPersonAuthUrl : overrideServer.metapersonApiUrl; } }

		public static string MetaPersonCreatorUrl { get { return overrideServer == null ? AvatarSDKMoveSettings.MetaPersonCreatorUrl : overrideServer.metapersonCreatorUrl; } }

		public static string SessionKeySuffix { get { return overrideServer == null ? string.Empty : "_" + overrideServer.name.ToLowerInvariant(); } }

		public static void SetOverride(ServerEndpoints server)
		{
			if (server == null && overrideServer == null)
				return;

			overrideServer = server;
			AuthUtils.RaiseSessionChanged();
		}

		public static ClientCredentials LoadClientCredentials()
		{
			return overrideServer == null
				? AuthUtils.LoadClientCredentials()
				: new ClientCredentials(overrideServer.clientId, overrideServer.clientSecret);
		}
	}
}
