package com.atridad.ascently.data.model

import androidx.compose.runtime.Immutable
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.atridad.ascently.utils.DateFormatUtils
import kotlinx.serialization.Serializable

@Immutable
@Entity(tableName = "gyms")
@Serializable
data class Gym(
    @PrimaryKey val id: String,
    val name: String,
    val location: String? = null,
    val supportedClimbTypes: List<ClimbType>,
    val difficultySystems: List<DifficultySystem>,
    val customDifficultyGrades: List<String> = emptyList(),
    val notes: String? = null,
    val createdAt: String,
    val updatedAt: String,
) {
    companion object {
        fun create(
            name: String,
            location: String? = null,
            supportedClimbTypes: List<ClimbType>,
            difficultySystems: List<DifficultySystem>,
            customDifficultyGrades: List<String> = emptyList(),
            notes: String? = null,
        ): Gym {
            val now = DateFormatUtils.nowISO8601()
            return Gym(
                id = java.util.UUID.randomUUID().toString(),
                name = name,
                location = location,
                supportedClimbTypes = supportedClimbTypes,
                difficultySystems = difficultySystems,
                customDifficultyGrades = customDifficultyGrades,
                notes = notes,
                createdAt = now,
                updatedAt = now,
            )
        }
    }
}
