from sqlalchemy import Column, String, Text, Float, Date, Boolean, Integer, DateTime
from sqlalchemy.sql import func
from app.core.database import Base
import uuid

def generate_uuid():
    return str(uuid.uuid4())

class SeekInfo(Base):
    __tablename__ = "seek_info"

    id = Column(String(36), primary_key=True, default=generate_uuid)
    user_id = Column(String(36), nullable=False, index=True)
    
    # 标题和内容
    title = Column(String(255), nullable=False)
    content = Column(Text, nullable=True)
    
    # 期望条件（求购条件）
    expect_category = Column(String(100), nullable=True)  # 期望类别
    expect_version = Column(String(100), nullable=True)  # 期望版别
    expect_packaging = Column(String(100), nullable=True)  # 期望包装
    expect_number = Column(String(50), nullable=True)  # 期望号码
    expect_price_min = Column(Float, nullable=True)  # 期望最低价
    expect_price_max = Column(Float, nullable=True)  # 期望最高价
    
    # 匹配状态
    status = Column(String(20), default="active")  # active/closed/expired
    is_matched = Column(String(10), default="false")  # 是否已匹配
    matched_user_id = Column(String(36), nullable=True)  # 匹配的用户ID
    matched_contact = Column(String(100), nullable=True)  # 匹配的联系方式
    
    # 统计
    view_count = Column(Integer, default=0)
    contact_count = Column(Integer, default=0)
    
    # 时间
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())