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 PluralOperandsLib: Library {
    fun icu4x_PluralOperands_destroy_mv1(handle: Pointer)
    fun icu4x_PluralOperands_from_string_mv1(s: Slice): ResultPointerInt
    fun icu4x_PluralOperands_from_int64_mv1(i: Long): Pointer
    fun icu4x_PluralOperands_from_fixed_decimal_mv1(x: Pointer): Pointer
}
/** See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/2.2.0/icu/plurals/struct.PluralOperands.html) for more information.
*/
class PluralOperands 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 var owned: Boolean,
)  {

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

    private class PluralOperandsCleaner(val handle: Pointer, val lib: PluralOperandsLib) : Runnable {
        override fun run() {
            lib.icu4x_PluralOperands_destroy_mv1(handle)
        }
    }
    private fun registerCleaner() {
        CLEANER.register(this, PluralOperands.PluralOperandsCleaner(handle, PluralOperands.lib));
    }

    companion object {
        internal val libClass: Class<PluralOperandsLib> = PluralOperandsLib::class.java
        internal val lib: PluralOperandsLib = Native.load("icu4x", libClass)
        @JvmStatic
        
        /** Construct for a given string representing a number
        *
        *See the [Rust documentation for `from_str`](https://docs.rs/icu/2.2.0/icu/plurals/struct.PluralOperands.html#method.from_str) for more information.
        */
        fun fromString(s: String): Result<PluralOperands> {
            val sSliceMemory = PrimitiveArrayTools.borrowUtf8(s)
            
            val returnVal = lib.icu4x_PluralOperands_from_string_mv1(sSliceMemory.slice);
            try {
                val nativeOkVal = returnVal.getNativeOk();
                if (nativeOkVal != null) {
                    val selfEdges: List<Any> = listOf()
                    val handle = nativeOkVal 
                    val returnOpaque = PluralOperands(handle, selfEdges, true)
                    return returnOpaque.ok()
                } else {
                    return DecimalParseErrorError(DecimalParseError.fromNative(returnVal.getNativeErr()!!)).err()
                }
            } finally {
                sSliceMemory.close()
            }
        }
        @JvmStatic
        
        /** Construct for a given integer
        */
        fun from(i: Long): PluralOperands {
            
            val returnVal = lib.icu4x_PluralOperands_from_int64_mv1(i);
            val selfEdges: List<Any> = listOf()
            val handle = returnVal 
            val returnOpaque = PluralOperands(handle, selfEdges, true)
            return returnOpaque
        }
        @JvmStatic
        
        /** Construct from a `FixedDecimal`
        *
        *Retains at most 18 digits each from the integer and fraction parts.
        */
        fun fromFixedDecimal(x: Decimal): PluralOperands {
            
            val returnVal = lib.icu4x_PluralOperands_from_fixed_decimal_mv1(x.handle);
            val selfEdges: List<Any> = listOf()
            val handle = returnVal 
            val returnOpaque = PluralOperands(handle, selfEdges, true)
            return returnOpaque
        }
    }

}