@file:Suppress("FunctionName") package expo.modules.kotlin.functions import expo.modules.kotlin.component6 import expo.modules.kotlin.component7 import expo.modules.kotlin.component8 import expo.modules.kotlin.types.enforceType import expo.modules.kotlin.types.toArgsArray import expo.modules.kotlin.types.toReturnType class FunctionBuilder(@PublishedApi internal val name: String) { @PublishedApi internal var functionComponent: SyncFunctionComponent? = null @JvmName("BodyWithoutArgs") inline fun Body( crossinline body: () -> Any? ): SyncFunctionComponent { return SyncFunctionComponent(name, emptyArray(), toReturnType()) { body() }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: () -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, emptyArray(), toReturnType()) { body() }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0) -> enforceType(p0) body(p0) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1) -> enforceType(p0, p1) body(p0, p1) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1, p2: P2) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1, p2) -> enforceType(p0, p1, p2) body(p0, p1, p2) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1, p2, p3) -> enforceType(p0, p1, p2, p3) body(p0, p1, p2, p3) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1, p2, p3, p4) -> enforceType(p0, p1, p2, p3, p4) body(p0, p1, p2, p3, p4) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1, p2, p3, p4, p5) -> enforceType(p0, p1, p2, p3, p4, p5) body(p0, p1, p2, p3, p4, p5) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1, p2, p3, p4, p5, p6) -> enforceType(p0, p1, p2, p3, p4, p5, p6) body(p0, p1, p2, p3, p4, p5, p6) }.also { functionComponent = it } } inline fun Body( name: String, crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R ): SyncFunctionComponent { return SyncFunctionComponent(name, toArgsArray(), toReturnType()) { (p0, p1, p2, p3, p4, p5, p6, p7) -> enforceType(p0, p1, p2, p3, p4, p5, p6, p7) body(p0, p1, p2, p3, p4, p5, p6, p7) }.also { functionComponent = it } } internal fun build() = requireNotNull(functionComponent) }