from sqlalchemy import Column, String, Numeric, Date, DateTime, BigInteger
from sqlalchemy.orm import declarative_base
from datetime import datetime

Base = declarative_base()


class User(Base):
    __tablename__ = "users"
    id = Column(BigInteger, primary_key=True)
    name = Column(String)
    email = Column(String, unique=True)
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now)


class LineUser(Base):
    __tablename__ = "line_users"
    id = Column(BigInteger, primary_key=True)
    line_user_id = Column(String, unique=True)
    user_id = Column(BigInteger)
    created_at = Column(DateTime, default=datetime.now)


class Category(Base):
    __tablename__ = "categories"
    id = Column(BigInteger, primary_key=True)
    user_id = Column(BigInteger)
    parent_id = Column(BigInteger, nullable=True)
    name = Column(String)
    color = Column(String, default='#3B82F6')
    icon = Column(String, nullable=True)
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now)


class CategoryRule(Base):
    __tablename__ = "category_rules"
    id = Column(BigInteger, primary_key=True)
    user_id = Column(BigInteger)
    category_id = Column(BigInteger)
    keyword = Column(String)
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now)


class Expense(Base):
    __tablename__ = "expenses"
    id = Column(BigInteger, primary_key=True)
    user_id = Column(BigInteger)
    category_id = Column(BigInteger, nullable=True)
    amount = Column(Numeric(10, 2))
    note = Column(String, nullable=True)
    invoice_number = Column(String, nullable=True)
    seller_name = Column(String, nullable=True)
    item_name = Column(String, nullable=True)
    date = Column(Date)
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now)