"""Add wp_disabled_rules table for WordPress-specific disabled rules.

This table stores disabled WordPress protection rules with a scope-based design
supporting global and domain-level disables.
"""

import peewee as pw


def migrate(migrator, database, fake=False, **kwargs):
    class WPDisabledRule(pw.Model):
        class Meta:
            db_table = "wp_disabled_rules"
            indexes = ((("rule_id", "scope", "scope_value"), True),)

        id = pw.PrimaryKeyField()
        rule_id = pw.CharField(null=False)
        scope = pw.CharField(null=False)
        scope_value = pw.CharField(null=True)
        disabled_at = pw.FloatField(null=False)
        source = pw.CharField(null=False)
        created_by_user_id = pw.IntegerField(null=False)

    migrator.create_model(WPDisabledRule)


def rollback(migrator, database, fake=False, **kwargs):
    WPDisabledRule = migrator.orm["wp_disabled_rules"]
    migrator.remove_model(WPDisabledRule)
