package com.jishisongfu.duobibi.data.db

import androidx.room.Entity
import androidx.room.PrimaryKey

/**
 * 降价提醒雷达的监控对象。统一承载两种场景(把旧"心愿单 + 价保"合并为一个模型):
 *   - WANT  (想买的):设一个心理价 [targetPrice],后台查价跌到 ≤ 心理价时提醒"降到心理价了"
 *   - BOUGHT(已买的):记下 [purchasePrice],后台查价跌破买价时提醒"可申请价保"
 *
 * 后台查价复用后端 `/api/v1/track-price`(LLM 估当前价 + 哈希抖动)。
 * track-price 的 savings = anchor - current:WANT 用 targetPrice 当 anchor,BOUGHT 用 purchasePrice。
 */
@Entity(tableName = "price_alert")
data class PriceAlert(
    @PrimaryKey(autoGenerate = true) val id: Long = 0,
    val title: String,
    /** 平台中文名;WANT 可不填(任意平台到价都提醒)*/
    val platform: String? = null,
    /** [AlertMode] */
    val mode: String = AlertMode.WANT,
    /** WANT:心理价 */
    val targetPrice: Double? = null,
    /** BOUGHT:购买价 */
    val purchasePrice: Double? = null,
    /** BOUGHT:购买时间(ms)*/
    val purchaseAt: Long? = null,
    val lastCheckedAt: Long? = null,
    val lastCurrentPrice: Double? = null,
    /** "down" / "flat" / "up" */
    val lastTrend: String? = null,
    /** anchor - lastCurrentPrice;> 0 = 已到价 / 可申请 */
    val lastSavings: Double? = null,
    /** [AlertStatus] */
    val status: String = AlertStatus.ACTIVE,
    val createdAt: Long,
    /** 首启注入的示例数据标记;清除示例数据时按此字段批量删 */
    val isDemo: Boolean = false,
)

object AlertMode {
    const val WANT = "want"     // 想买的
    const val BOUGHT = "bought" // 已买的
}

object AlertStatus {
    const val ACTIVE = "active"   // 监控中
    const val STOPPED = "stopped" // 用户主动停止
    const val DONE = "done"       // 已买到 / 已申请价保,归档
}
