using System;
using Foundation;
using SII.SDK.Maui.Printer;
using UIKit;

namespace Sample
{
    partial class Function
    {
        // Gets the current language setting set on the device.
        public partial String GetCurrentLanguage()
        {
            return Foundation.NSLocale.PreferredLanguages[0];
        }

        public partial Task CheckStoragePermissions()
        {
            // On iOS, permissions are not required.
            return Task.CompletedTask;
        }

        private partial Task CheckBluetoothPermissions(PortType portType)
        {
            // On iOS, permissions are not required.
            return Task.CompletedTask;
        }

        // Get UIKit.UIImage instance from stream.
        private partial object GetPlatformImageData(string filePath)
        {
            try
            {
                using (FileStream fs = System.IO.File.OpenRead(filePath))
                {
                    using (var imageData = NSData.FromStream(fs))
                    {
                        var image = UIImage.LoadFromData(imageData);
                        return image;
                    }
                }
            }
            catch
            {
                return null;
            }
        }

        // Dispose UIKit.UIImage instance.
        private partial bool DisposePlatformImageData(object imageObject)
        {
            try
            {
                if (imageObject is UIImage image)
                {
                    image.Dispose();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

