package com.fabledsword.minstrel.api.endpoints

import com.fabledsword.minstrel.models.wire.AdminTagSourceWire
import com.fabledsword.minstrel.models.wire.AdminTagSourcesListWire
import com.fabledsword.minstrel.models.wire.TestTagSourceWire
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Path

/**
 * Retrofit interface for `/api/admin/tag-sources` (#1521) — the admin
 * surface for the tag-enrichment provider settings (#1490). Mirrors the
 * web integrations "Tag enrichment sources" card. Same shape as the
 * cover-sources admin surface; kept independent so a new tag source is
 * added without touching art settings.
 */
interface AdminTagSourcesApi {
    @GET("api/admin/tag-sources")
    suspend fun list(): AdminTagSourcesListWire

    @PATCH("api/admin/tag-sources/{id}")
    suspend fun update(@Path("id") id: String, @Body body: UpdateTagSourceBody): AdminTagSourceWire

    @POST("api/admin/tag-sources/{id}/test")
    suspend fun test(@Path("id") id: String): TestTagSourceWire
}

/**
 * PATCH body. Both fields are nullable + default-null so kotlinx omits the
 * untouched one (the server reads a missing/null field as "leave
 * unchanged"): send only `enabled` to toggle, only `apiKey` to set a key.
 */
@Serializable
data class UpdateTagSourceBody(
    val enabled: Boolean? = null,
    @SerialName("api_key") val apiKey: String? = null,
)
