// DO NOT EDIT! This is an autogenerated file. All changes will be
// overwritten!

//	Copyright (c) 2023 Vidyo, Inc. All rights reserved.


using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;

namespace VidyoClient
{
	public class LoggerCategoryFactory
	{
		public static LoggerCategory Create()
		{
			return new LoggerCategory(IntPtr.Zero);
		}
		public static void Destroy(LoggerCategory obj)
		{
		}
	}
	/// <summary>
	/// 
	/// </summary>
	public class LoggerCategory {
#if __IOS__
		const string importLib = "__Internal";
#else
		const string importLib = "libVidyoClient";
#endif
		private IntPtr objPtr; // opaque VidyoLoggerCategory reference.
		public IntPtr GetObjectPtr() {
			IntPtr nCategoryDescr = MarshalPtrToUtf8.GetInstance().MarshalManagedToNative(categoryDescr ?? string.Empty);
			IntPtr nLevels = Marshal.AllocHGlobal(Marshal.SizeOf<IntPtr>() * levels.Count);
			int nLevelsSize = 0;
			IntPtr nName = MarshalPtrToUtf8.GetInstance().MarshalManagedToNative(name ?? string.Empty);

			foreach (String iter in levels) {
				Marshal.WriteIntPtr(nLevels + (nLevelsSize * Marshal.SizeOf<IntPtr>()), MarshalPtrToUtf8.GetInstance().MarshalManagedToNative(iter ?? string.Empty));
				nLevelsSize++;
			}

			VidyoLoggerCategorySetcategoryDescrNative(objPtr, nCategoryDescr);
			VidyoLoggerCategorySetlevelsNative(objPtr, nLevels, nLevelsSize);
			VidyoLoggerCategorySetnameNative(objPtr, nName);

			for (int i = 0; i < nLevelsSize; i++) {
				Marshal.FreeHGlobal(Marshal.ReadIntPtr(nLevels + (i * Marshal.SizeOf<IntPtr>())));
			}

			Marshal.FreeHGlobal(nName);
			Marshal.FreeHGlobal(nLevels);
			Marshal.FreeHGlobal(nCategoryDescr);
			return objPtr;
		}
		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr VidyoLoggerCategoryGetcategoryDescrNative(IntPtr obj);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern void VidyoLoggerCategorySetcategoryDescrNative(IntPtr obj, IntPtr categoryDescr);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr VidyoLoggerCategoryGetlevelsNative(IntPtr obj);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern void VidyoLoggerCategorySetlevelsNative(IntPtr obj, IntPtr levels, int size);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr VidyoLoggerCategoryGetlevelsArrayNative(IntPtr obj, ref int size);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern void VidyoLoggerCategoryFreelevelsArrayNative(IntPtr obj, int size);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr VidyoLoggerCategoryGetnameNative(IntPtr obj);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		private static extern void VidyoLoggerCategorySetnameNative(IntPtr obj, IntPtr name);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		public static extern IntPtr VidyoLoggerCategoryConstructCopyNative(IntPtr obj);

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		public static extern IntPtr VidyoLoggerCategoryConstructDefaultNative();

		[DllImport(importLib, CallingConvention = CallingConvention.Cdecl)]
		public static extern void VidyoLoggerCategoryDestructNative(IntPtr obj);

		/// <summary>
		/// 
		/// </summary>
		public String categoryDescr;
		/// <summary>
		/// 
		/// </summary>
		public List<String> levels;
		/// <summary>
		/// 
		/// </summary>
		public String name;
		public LoggerCategory(IntPtr obj){
			if(obj == IntPtr.Zero) {
				objPtr = VidyoLoggerCategoryConstructDefaultNative();
			}
			else {
				objPtr = VidyoLoggerCategoryConstructCopyNative(obj);
			}

			List<String> csLevels = new List<String>();
			var nLevelsSize = 0;
			var nLevels = VidyoLoggerCategoryGetlevelsArrayNative(VidyoLoggerCategoryGetlevelsNative(objPtr), ref nLevelsSize);
			var nLevelsIndex = 0;
			while (nLevelsIndex < nLevelsSize) {
				csLevels.Add((string)MarshalPtrToUtf8.GetInstance().MarshalNativeToManaged(Marshal.ReadIntPtr(nLevels + (nLevelsIndex * Marshal.SizeOf(nLevels)))));
				nLevelsIndex++;
			}

			categoryDescr = (string)MarshalPtrToUtf8.GetInstance().MarshalNativeToManaged(VidyoLoggerCategoryGetcategoryDescrNative(objPtr));
			levels = csLevels;
			name = (string)MarshalPtrToUtf8.GetInstance().MarshalNativeToManaged(VidyoLoggerCategoryGetnameNative(objPtr));
			VidyoLoggerCategoryFreelevelsArrayNative(nLevels, nLevelsSize);
		}
		~LoggerCategory() {
			VidyoLoggerCategoryDestructNative(objPtr);
		 }
	};
}
