from sqlalchemy import Column, Integer, String, BigInteger, Enum, DateTime, Boolean, SmallInteger
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func

Base = declarative_base()

class WebhookSubscriptions(Base):
    __tablename__ = "webhook_subscriptions"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    notification_store = Column(Enum('apple', 'android'), nullable=False, default='apple')
    notification_type = Column(String(255), nullable=True)
    environment = Column(String(255), nullable=True)
    auto_renew_product_id = Column(String(255), nullable=True)
    auto_renew_status = Column(SmallInteger, nullable=True)  # tinyint(1)
    auto_renew_status_change_date_ms = Column(BigInteger, nullable=True)
    password = Column(String(255), nullable=True)
    bundle_id = Column(String(255), nullable=True)
    bundle_version = Column(String(255), nullable=True)
    in_app_ownership_type = Column(Enum('PURCHASED', 'FAMILY_SHARED'), nullable=True)
    purchase_date_ms = Column(BigInteger, nullable=True)
    transaction_id = Column(String(255), nullable=True)
    original_purchase_date_ms = Column(BigInteger, nullable=True)
    original_transaction_id = Column(String(255), nullable=True)
    quantity = Column(Integer, nullable=False, default=1)
    expires_date_ms = Column(BigInteger, nullable=True)
    is_expired = Column(SmallInteger, nullable=True)  # tinyint(1)
    product_id = Column(String(255), nullable=True)
    is_trial_period = Column(SmallInteger, nullable=True)  # tinyint(1)
    is_in_intro_offer_period = Column(SmallInteger, nullable=True)  # tinyint(1)
    expiration_intent = Column(String(255), nullable=True)
    subtype = Column(String(255), nullable=True)
    consumption_request_status = Column(String(255), nullable=True)
    cancellation_date_ms = Column(BigInteger, nullable=True)
    created_at = Column(DateTime(timezone=True), nullable=False, server_default=func.now())
