package com.tt.honeyDue.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
 * Represents a task template fetched from the backend API.
 * Users can select these when adding a new task to auto-fill form fields.
 */
@Serializable
data class TaskTemplate(
    val id: Int,
    val title: String,
    val description: String = "",
    @SerialName("category_id") val categoryId: Int? = null,
    val category: TaskCategory? = null,
    @SerialName("frequency_id") val frequencyId: Int? = null,
    val frequency: TaskFrequency? = null,
    @SerialName("icon_ios") val iconIos: String = "",
    @SerialName("icon_android") val iconAndroid: String = "",
    val tags: List<String> = emptyList(),
    @SerialName("display_order") val displayOrder: Int = 0,
    @SerialName("is_active") val isActive: Boolean = true
) {
    /**
     * Human-readable frequency display
     */
    val frequencyDisplay: String
        get() = frequency?.displayName ?: "One time"

    /**
     * Category name for display
     */
    val categoryName: String
        get() = category?.name ?: "Uncategorized"
}

/**
 * Response for grouped templates by category
 */
@Serializable
data class TaskTemplateCategoryGroup(
    @SerialName("category_name") val categoryName: String,
    @SerialName("category_id") val categoryId: Int? = null,
    val templates: List<TaskTemplate>,
    val count: Int
)

/**
 * Response for all templates grouped by category
 */
@Serializable
data class TaskTemplatesGroupedResponse(
    val categories: List<TaskTemplateCategoryGroup>,
    @SerialName("total_count") val totalCount: Int
)
