<commit_before>@file:Suppress("unused")

package coil.request

import android.content.Context
import android.graphics.Bitmap
import android.graphics.ColorSpace
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.lifecycle.Lifecycle
import coil.DefaultRequestOptions
import coil.ImageLoader
import coil.decode.DataSource
import coil.decode.Decoder
import coil.size.Scale
import coil.size.SizeResolver
import coil.target.Target
import coil.transform.Transformation
import coil.util.getDrawableCompat
import kotlinx.coroutines.CoroutineDispatcher
import okhttp3.Headers

/**
 * A value object that represents an image request.
 *
 * @see LoadRequest
 * @see GetRequest
 */
sealed class Request {

    abstract val data: Any?

    abstract val target: Target?
    abstract val lifecycle: Lifecycle?
    abstract val crossfadeMillis: Int

    abstract val key: String?
    abstract val listener: Listener?
    abstract val sizeResolver: SizeResolver?
    abstract val scale: Scale?
    abstract val decoder: Decoder?
    abstract val dispatcher: CoroutineDispatcher
    abstract val transformations: List<Transformation>
    abstract val bitmapConfig: Bitmap.Config
    abstract val colorSpace: ColorSpace?
    abstract val headers: Headers
    abstract val parameters: Parameters

    abstract val networkCachePolicy: CachePolicy
    abstract val diskCachePolicy: CachePolicy
    abstract val memoryCachePolicy: CachePolicy

    abstract val allowHardware: Boolean
    abstract val allowRgb565: Boolean

    abstract val placeholder: Drawable?
    abstract val error: Drawable?

    /**
     * A set of callbacks for a [Request]. All callbacks are guaranteed to be called on the main thread.
     */
    interface Listener {

        /**
         * Called when the request is dispatched and starts loading the image.
         */
        fun onStart(data: Any) {}

        /**
         * Called when the request successfully loads the image.
         */
        fun onSuccess(data: Any, source: DataSource) {}

        /**
         * Called when the request is cancelled.
         */
        fun onCancel(data: Any) {}

        /**
         * Called when the request fails to load the image.
         */
        fun onError(data: Any, throwable: Throwable) {}
    }
}

/**
 * A value object that represents a *load* image request.
 *
 * Instances can be created ad hoc:
 * ```
 * imageLoader.load(context, "https://www.example.com/image.jpg") {
 *     crossfade(true)
 *     target(imageView)
 * }
 * ```
 *
 * Or instances can be created separately from the call that executes them:
 * ```
 * val request = LoadRequest(context, imageLoader.defaults) {
 *     data("https://www.example.com/image.jpg")
 *     crossfade(true)
 *     target(imageView)
 * }
 * imageLoader.load(request)<commit_msg>Annotate Request.Listener methods with @MainThread .<commit_after>@file:Suppress("unused")

package coil.request

import android.content.Context
import android.graphics.Bitmap
import android.graphics.ColorSpace
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.annotation.MainThread
import androidx.lifecycle.Lifecycle
import coil.DefaultRequestOptions
import coil.ImageLoader
import coil.decode.DataSource
import coil.decode.Decoder
import coil.size.Scale
import coil.size.SizeResolver
import coil.target.Target
import coil.transform.Transformation
import coil.util.getDrawableCompat
import kotlinx.coroutines.CoroutineDispatcher
import okhttp3.Headers

/**
 * A value object that represents an image request.
 *
 * @see LoadRequest
 * @see GetRequest
 */
sealed class Request {

    abstract val data: Any?

    abstract val target: Target?
    abstract val lifecycle: Lifecycle?
    abstract val crossfadeMillis: Int

    abstract val key: String?
    abstract val listener: Listener?
    abstract val sizeResolver: SizeResolver?
    abstract val scale: Scale?
    abstract val decoder: Decoder?
    abstract val dispatcher: CoroutineDispatcher
    abstract val transformations: List<Transformation>
    abstract val bitmapConfig: Bitmap.Config
    abstract val colorSpace: ColorSpace?
    abstract val headers: Headers
    abstract val parameters: Parameters

    abstract val networkCachePolicy: CachePolicy
    abstract val diskCachePolicy: CachePolicy
    abstract val memoryCachePolicy: CachePolicy

    abstract val allowHardware: Boolean
    abstract val allowRgb565: Boolean

    abstract val placeholder: Drawable?
    abstract val error: Drawable?

    /**
     * A set of callbacks for a [Request].
     */
    interface Listener {

        /**
         * Called when the request is dispatched and starts loading the image.
         */
        @MainThread
        fun onStart(data: Any) {}

        /**
         * Called when the request successfully loads the image.
         */
        @MainThread
        fun onSuccess(data: Any, source: DataSource) {}

        /**
         * Called when the request is cancelled.
         */
        @MainThread
        fun onCancel(data: Any) {}

        /**
         * Called when the request fails to load the image.
         */
        @MainThread
        fun onError(data: Any, throwable: Throwable) {}
    }
}

/**
 * A value object that represents a *load* image request.
 *
 * Instances can be created ad hoc:
 * ```
 * imageLoader.load(context, "https://www.example.com/image.jpg") {
 *     crossfade(true)
 *     target(imageView)
 * }
 * ```
 *
 * Or instances can be created separately from the call that executes them:
 * ```
 * val request = LoadRequest(context, imageLoader.defaults) {
 *     data("https://www.example.com/image.jpg")
 *     crossfade(true)
 *     target(imageView)
 * }
 * imageLoader.load(request)
{'fraction_non_alphanumeric': 0.0829141370338248, 'fraction_numerical': 0.0013876843018213356, 'mean_word_length': 3.1422413793103448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2359749', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1502, 'n_words': 497}