/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package com.runicgateway.app.data.api

import com.runicgateway.app.data.api.dto.AdminDashboardDto
import com.runicgateway.app.data.api.dto.AdminPostDto
import com.runicgateway.app.data.api.dto.BanRequest
import com.runicgateway.app.data.api.dto.BroadcastRequest
import com.runicgateway.app.data.api.dto.KickRequest
import com.runicgateway.app.data.api.dto.PageRespondRequest
import com.runicgateway.app.data.api.dto.PostCreateRequest
import com.runicgateway.app.data.api.dto.PublishRequest
import com.runicgateway.app.data.api.dto.SiteModeRequest
import com.runicgateway.app.data.api.dto.SiteModeStateDto
import com.runicgateway.app.data.api.dto.SupportPageDto
import com.runicgateway.app.data.api.dto.UnbanRequest
import com.runicgateway.app.data.api.dto.AdminWikiCategoryDto
import com.runicgateway.app.data.api.dto.WikiCategoryRequest
import com.runicgateway.app.data.api.dto.AdminWikiTagDto
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.PUT
import retrofit2.http.POST
import retrofit2.http.Path

/**
 * The M10 staff-operations surface over `/api/v1/admin/…` (PLAN.md §1, §6.4). On
 * the authed client — every call carries the bearer, and the backend re-checks the
 * caller's role on every request (`staffOnly` / `modAccess` / `adminOnly`), so a
 * demoted user is refused server-side even if a stale menu still showed the entry.
 *
 * Grows one group at a time (dashboard first); moderation, support, and content
 * endpoints are added with their screens.
 */
interface AdminApi {

    /** `GET /admin/dashboard` — summary counts + site mode (any staff role). */
    @GET("api/v1/admin/dashboard")
    suspend fun dashboard(): AdminDashboardDto

    /** `PUT /admin/site-mode` — switch live/maintenance (admin only; 403 otherwise). */
    @PUT("api/v1/admin/site-mode")
    suspend fun setSiteMode(@Body body: SiteModeRequest): SiteModeStateDto

    // ── Content: news posts (any staff role) ──────────────────────────────
    @GET("api/v1/admin/posts")
    suspend fun posts(): List<AdminPostDto>

    @POST("api/v1/admin/posts")
    suspend fun createPost(@Body body: PostCreateRequest): AdminPostDto

    @PATCH("api/v1/admin/posts/{id}/publish")
    suspend fun publishPost(@Path("id") id: Long, @Body body: PublishRequest): AdminPostDto

    @DELETE("api/v1/admin/posts/{id}")
    suspend fun deletePost(@Path("id") id: Long): Response<Unit>

    // ── Content: wiki taxonomy (any staff role) ───────────────────────────
    @GET("api/v1/admin/wiki/categories")
    suspend fun wikiCategories(): List<AdminWikiCategoryDto>

    @POST("api/v1/admin/wiki/categories")
    suspend fun createWikiCategory(@Body body: WikiCategoryRequest): AdminWikiCategoryDto

    @DELETE("api/v1/admin/wiki/categories/{id}")
    suspend fun deleteWikiCategory(@Path("id") id: Long): Response<Unit>

    @GET("api/v1/admin/wiki/tags")
    suspend fun wikiTags(): List<AdminWikiTagDto>

    // ── Moderation: shard write plane (admin/moderator) ───────────────────
    @POST("api/v1/admin/shard/kick")
    suspend fun kick(@Body body: KickRequest): Response<Unit>

    @POST("api/v1/admin/shard/ban")
    suspend fun ban(@Body body: BanRequest): Response<Unit>

    @POST("api/v1/admin/shard/unban")
    suspend fun unban(@Body body: UnbanRequest): Response<Unit>

    @POST("api/v1/admin/shard/broadcast")
    suspend fun broadcast(@Body body: BroadcastRequest): Response<Unit>

    // ── Support queue: help pages (admin/moderator) ───────────────────────
    @GET("api/v1/admin/shard/pages")
    suspend fun supportPages(): List<SupportPageDto>

    @POST("api/v1/admin/shard/pages/{id}/respond")
    suspend fun respondPage(@Path("id") id: String, @Body body: PageRespondRequest): Response<Unit>

    @POST("api/v1/admin/shard/pages/{id}/close")
    suspend fun closePage(@Path("id") id: String): Response<Unit>
}
