from app.extensions import db


class MerchantMapping(db.Model):
    """
    Full Phase 2 schema required in Phase 1 (AR-6).
    Prevents a live-data migration when staging_pipeline.py is wired in Epic 9.
    """
    __tablename__ = 'merchant_mappings'

    id = db.Column(db.Integer, primary_key=True)
    raw_pattern = db.Column(db.Text, nullable=False)
    normalized = db.Column(db.Text, nullable=False)
    user_confirmed = db.Column(db.Boolean, nullable=False, default=False)  # AR-6: full Phase 2 schema

    category_id = db.Column(db.Integer, db.ForeignKey('categories.id', ondelete='SET NULL'), nullable=True)
    category = db.relationship('Category', back_populates='merchant_mappings')
