package org.unicode.icu4x;
import com.sun.jna.Callback
import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure

internal interface LocaleFallbackerWithConfigLib: Library {
    fun icu4x_LocaleFallbackerWithConfig_destroy_mv1(handle: Pointer)
    fun icu4x_LocaleFallbackerWithConfig_config_mv1(handle: Pointer): LocaleFallbackConfigNative
    fun icu4x_LocaleFallbackerWithConfig_fallback_for_locale_mv1(handle: Pointer, locale: Pointer): Pointer
}
/** An object that runs the ICU4X locale fallback algorithm with specific configurations.
*
*See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/2.2.0/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html) for more information.
*/
class LocaleFallbackerWithConfig internal constructor (
    internal val handle: Pointer,
    // These ensure that anything that is borrowed is kept alive and not cleaned
    // up by the garbage collector.
    internal val selfEdges: List<Any>,
    internal val aEdges: List<Any?>,
    internal var owned: Boolean,
)  {

    init {
        if (this.owned) {
            this.registerCleaner()
        }
    }

    private class LocaleFallbackerWithConfigCleaner(val handle: Pointer, val lib: LocaleFallbackerWithConfigLib) : Runnable {
        override fun run() {
            lib.icu4x_LocaleFallbackerWithConfig_destroy_mv1(handle)
        }
    }
    private fun registerCleaner() {
        CLEANER.register(this, LocaleFallbackerWithConfig.LocaleFallbackerWithConfigCleaner(handle, LocaleFallbackerWithConfig.lib));
    }

    companion object {
        internal val libClass: Class<LocaleFallbackerWithConfigLib> = LocaleFallbackerWithConfigLib::class.java
        internal val lib: LocaleFallbackerWithConfigLib = Native.load("icu4x", libClass)
    }
    
    /** Returns the associated config.
    *
    *See the [Rust documentation for `config`](https://docs.rs/icu/2.2.0/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html#method.config) for more information.
    */
    fun config(): LocaleFallbackConfig {
        
        val returnVal = lib.icu4x_LocaleFallbackerWithConfig_config_mv1(handle);
        val returnStruct = LocaleFallbackConfig.fromNative(returnVal)
        return returnStruct
    }
    
    /** Creates an iterator from a locale with each step of fallback.
    *
    *See the [Rust documentation for `fallback_for`](https://docs.rs/icu/2.2.0/icu/locale/fallback/struct.LocaleFallbacker.html#method.fallback_for) for more information.
    */
    fun fallbackForLocale(locale: Locale): LocaleFallbackIterator {
        // This lifetime edge depends on lifetimes: 'a, 'b
        val aEdges: MutableList<Any> = mutableListOf(this);
        
        val returnVal = lib.icu4x_LocaleFallbackerWithConfig_fallback_for_locale_mv1(handle, locale.handle);
        val selfEdges: List<Any> = listOf()
        val handle = returnVal 
        val returnOpaque = LocaleFallbackIterator(handle, selfEdges, aEdges, true)
        return returnOpaque
    }

}