All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.algolia.search.dsl.rule.DSLPromotions.kt Maven / Gradle / Ivy

package com.algolia.search.dsl.rule

import com.algolia.search.dsl.DSL
import com.algolia.search.dsl.DSLParameters
import com.algolia.search.model.ObjectID
import com.algolia.search.model.rule.Promotion

/**
 * DSL for building a [List] of [Promotion].
 */
@DSLParameters
public class DSLPromotions(
    private val promotions: MutableList = mutableListOf()
) {

    /**
     * Add [this] to [promotions].
     */
    public operator fun Promotion.unaryPlus() {
        promotions += this
    }

    /**
     * Convenience method.
     */
    public operator fun String.invoke(position: Int): Promotion {
        return ObjectID(this).invoke(position)
    }

    /**
     * Create a [Promotion] with [this] and [position].
     */
    public operator fun ObjectID.invoke(position: Int): Promotion {
        return Promotion(this, position)
    }

    /**
     * Create a [Promotion] with [this] and [position].
     */
    public operator fun List.invoke(position: Int): Promotion {
        return Promotion(this, position)
    }

    public companion object : DSL> {

        override operator fun invoke(block: DSLPromotions.() -> Unit): List {
            return DSLPromotions().apply(block).promotions
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy