package com.aiosman.ravenow.data

import android.util.Log
import com.aiosman.ravenow.ConstVars
import com.aiosman.ravenow.data.api.ApiClient
import com.aiosman.ravenow.data.api.CreateReportRequestBody
import com.aiosman.ravenow.entity.ReportReasons
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

data class ReportReasonList(
    @SerializedName("reasons") var reasons: ArrayList<ReportReasons>
)

interface CommonService {
    suspend fun getReportReasons(): ReportReasonList
    suspend fun createReport(
        reportReasonId: Int,
        reportType: String,
        reportId: Int,
    )
}

class CommonServiceImpl : CommonService {
    private val dictService: DictService = DictServiceImpl()
    override suspend fun getReportReasons(): ReportReasonList {
        val dictItem = dictService.getDictByKey(ConstVars.DICT_KEY_REPORT_OPTIONS)
        val rawJson: String = dictItem.value as? String ?: throw Exception("parse report reasons error")
        val gson = Gson()
        val list = gson.fromJson(rawJson, ReportReasonList::class.java)
        return list
    }

    override suspend fun createReport(
        reportReasonId: Int,
        reportType: String,
        reportId: Int,
    ) {
       ApiClient.api.createReport(
           CreateReportRequestBody(
               reportType = reportType,
               reportId = reportId,
               reason = reportReasonId,
               extra = "",
               base64Images = emptyList()
           )
       )
    }

}