package com.pixelized.shared.lwa.protocol.rest

import kotlinx.serialization.Serializable

@Serializable
data class APIResponse<T>(
    val success: Boolean,
    val status: Int,
    val message: String?,
    val code: ErrorCode?,
    val data: T?,
) {
    @Serializable
    enum class ErrorCode {
        AlterationId,
        AlterationName,
        ItemId,
        InventoryId,
        ItemName,
        CharacterSheetId,
        MapId,
        Create,
        Active,
        Equip,
        Damage,
        Armor,
        Fatigue,
        Diminished,
        Count,
    }

    companion object {
        fun error(
            status: Int,
            code: ErrorCode? = null,
            message: String?,
        ) = APIResponse(
            success = false,
            status = status,
            code = code,
            message = message,
            data = null,
        )

        fun success(
            status: Int = OK,
        ) = APIResponse(
            success = true,
            status = status,
            code = null,
            message = null,
            data = null,
        )

        inline fun <reified T> success(
            status: Int = OK,
            data: T? = null,
        ) = APIResponse(
            success = true,
            status = status,
            code = null,
            message = null,
            data = data,
        )

        const val OK = 200
        const val BAD_REQUEST = 400
        const val INTERNAL_ERROR = 500
    }
}