package de.krisenvorrat.server.db

import org.jetbrains.exposed.sql.Table

internal object Inventories : Table("inventories") {
    val id = varchar("id", 36)
    val name = varchar("name", 255).default("")
    val createdAt = long("created_at")
    override val primaryKey = PrimaryKey(id)
}

internal object Users : Table("users") {
    val id = varchar("id", 36)
    val username = varchar("username", 255).uniqueIndex()
    val passwordHash = varchar("password_hash", 255)
    val createdAt = long("created_at")
    val isAdmin = bool("is_admin").default(false)
    val inventoryId = varchar("inventory_id", 36).nullable()

    override val primaryKey = PrimaryKey(id)
}

internal object Categories : Table("categories") {
    val pk = integer("pk").autoIncrement()
    val id = integer("id")
    val name = varchar("name", 255)
    val inventoryId = varchar("inventory_id", 36).nullable()

    override val primaryKey = PrimaryKey(pk)
}

internal object Locations : Table("locations") {
    val pk = integer("pk").autoIncrement()
    val id = integer("id")
    val name = varchar("name", 255)
    val inventoryId = varchar("inventory_id", 36).nullable()

    override val primaryKey = PrimaryKey(pk)
}

internal object Items : Table("items") {
    val id = varchar("id", 36)
    val name = varchar("name", 255)
    val categoryId = integer("category_id")
    val quantity = double("quantity")
    val unit = varchar("unit", 50)
    val unitPrice = double("unit_price")
    val kcalPerKg = integer("kcal_per_kg").nullable()
    val expiryDate = varchar("expiry_date", 10).nullable()
    val locationId = integer("location_id")
    val notes = text("notes")
    val lastUpdated = long("last_updated")
    val inventoryId = varchar("inventory_id", 36).nullable()

    override val primaryKey = PrimaryKey(id)
}

internal object Settings : Table("settings") {
    val id = integer("id").autoIncrement()
    val key = varchar("key", 255)
    val value = text("value")
    val inventoryId = varchar("inventory_id", 36).nullable()

    override val primaryKey = PrimaryKey(id)
}

internal object Messages : Table("messages") {
    val id = varchar("id", 36)
    val senderId = varchar("sender_id", 36)
    val receiverId = varchar("receiver_id", 36)
    val body = text("body")
    val sentAt = long("sent_at")
    val deliveredAt = long("delivered_at").nullable()
    override val primaryKey = PrimaryKey(id)
}

internal object DeletedItems : Table("deleted_items") {
    val id = integer("id").autoIncrement()
    val itemId = varchar("item_id", 36)
    val inventoryId = varchar("inventory_id", 36)
    val deletedAt = long("deleted_at")

    override val primaryKey = PrimaryKey(id)
}
