using System;
using System.Runtime.InteropServices;
using Tesseract.Interop;

namespace Tesseract
{
    
    
    
    public sealed class ChoiceIterator : DisposableBase
    {
        private readonly HandleRef _handleRef;
        
        internal ChoiceIterator(IntPtr handle)
        {
            _handleRef = new HandleRef(this, handle);
        }

        
        
        
        
        public bool Next()
        {
            VerifyNotDisposed();
            if (_handleRef.Handle == IntPtr.Zero)
                return false;
            return TessApi.Native.ChoiceIteratorNext(_handleRef) != 0;
        }

        
        
        
        
        
        
        
        public float GetConfidence()
        {
            VerifyNotDisposed();
            if (_handleRef.Handle == IntPtr.Zero)
                return 0f;

            return TessApi.Native.ChoiceIteratorGetConfidence(_handleRef);
        }

        
        
        
        
        public string GetText()
        {
            VerifyNotDisposed();
            if (_handleRef.Handle == IntPtr.Zero)            
                return String.Empty;
            
            return TessApi.ChoiceIteratorGetUTF8Text(_handleRef);
        }

        protected override void Dispose(bool disposing)
        {
            if (_handleRef.Handle != IntPtr.Zero)
            {
                TessApi.Native.ChoiceIteratorDelete(_handleRef);
            }
        }
    }
}
