package eu.friedcutlet.yokan.domain import kotlinx.serialization.Serializable import kotlin.jvm.JvmInline import kotlin.random.Random @Serializable @JvmInline value class ProfileId(val value: String) { init { require(value == "default" || Regex("p_[0-9a-f]{32}").matches(value)) { "Invalid profile ID" } } companion object { val Default = ProfileId("default") fun random(): ProfileId = ProfileId("p_" + Random.nextBytes(16).toHexString()) } } /** Only stable IDs enter paths/keys. Default aliases legacy locations; no adoption copy is needed. */ data class ProfileStorageNamespace(val id: ProfileId) { val relativeRoot: String? get() = if (id == ProfileId.Default) null else "profiles/${id.value}" val databaseRelativePath: String get() = relativeRoot?.let { "$it/yokan-room.db" } ?: "yokan-room.db" val browserSnapshotKey: String get() = if (id == ProfileId.Default) "yokan-database-v1" else "yokan-database-v1:${id.value}" fun ownedRoot(base: String): String = relativeRoot?.let { "${base.trimEnd('/')}/$it" } ?: base.trimEnd('/') }