package com.example.notesai.data.model

import android.annotation.SuppressLint
import kotlinx.serialization.Serializable

@Serializable
data class SerializableCategory(
    val id: String,
    val name: String,
    val gradientStart: Long,
    val gradientEnd: Long,
    val timestamp: Long,
    val isDeleted: Boolean = false,
    val isPinned: Boolean = false
)

@SuppressLint("UnsafeOptInUsageError")
@Serializable
data class SerializableNote(
    val id: String,
    val categoryId: String,
    val title: String,
    val description: String = "",
    val content: String = "",
    val timestamp: Long,
    val isArchived: Boolean,
    val isDeleted: Boolean,
    val isPinned: Boolean
)

// Extension functions untuk konversi
fun Category.toSerializable() = SerializableCategory(
    id = id,
    name = name,
    gradientStart = gradientStart,
    gradientEnd = gradientEnd,
    timestamp = timestamp,
    isDeleted = isDeleted,
    isPinned = isPinned
)

fun SerializableCategory.toCategory() = Category(
    id = id,
    name = name,
    gradientStart = gradientStart,
    gradientEnd = gradientEnd,
    timestamp = timestamp,
    isDeleted = isDeleted,
    isPinned = isPinned
)

fun Note.toSerializable() = SerializableNote(
    id = id,
    categoryId = categoryId,
    title = title,
    description = description,
    content = content,
    timestamp = timestamp,
    isArchived = isArchived,
    isDeleted = isDeleted,
    isPinned = isPinned
)

fun SerializableNote.toNote() = Note(
    id = id,
    categoryId = categoryId,
    title = title,
    description = description,
    content = content,
    timestamp = timestamp,
    isArchived = isArchived,
    isDeleted = isDeleted,
    isPinned = isPinned
)