package com.example.initiateaphonecallapp.data.model

import com.example.initiateaphonecallapp.enums.CallStatus
import com.google.gson.annotations.SerializedName
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

data class CallRecordUploadRequest(
    @SerializedName("phone")
    val phone: String,

    @SerializedName("duration")
    val duration: Long,

    @SerializedName("status")
    val status: Boolean,

    @SerializedName("fileUrl")
    val fileUrl: String?,

    @SerializedName("createTime")
    val createTime: String
) {
    companion object {
        fun fromCallRecord(callRecord: CallRecord, audioFileUrl: String? = null): CallRecordUploadRequest {
            return CallRecordUploadRequest(
                phone = callRecord.phoneNumber,
                duration = callRecord.duration,
                status = callRecord.status == CallStatus.COMPLETED, // 根据你的业务逻辑调整
                fileUrl = audioFileUrl ?: callRecord.audioFileUri,
                createTime = formatDateTimeForApi(callRecord.startTime)
            )
        }

        private fun formatDateTimeForApi(date: Date): String {
            val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault())
            return sdf.format(date)
        }
    }
}