-- Add persistent status effects table
DROP TABLE IF EXISTS player_status_effects CASCADE;

CREATE TABLE player_status_effects (
    id SERIAL PRIMARY KEY,
    character_id INTEGER NOT NULL REFERENCES characters(id) ON DELETE CASCADE,
    effect_name VARCHAR(50) NOT NULL,
    effect_icon VARCHAR(10) NOT NULL,
    damage_per_tick INTEGER NOT NULL DEFAULT 0,
    effect_type VARCHAR(20) DEFAULT 'damage',
    value INTEGER DEFAULT 0,
    ticks_remaining INTEGER NOT NULL,
    persist_after_combat BOOLEAN DEFAULT FALSE,
    source VARCHAR(50),
    applied_at FLOAT NOT NULL,
    CONSTRAINT valid_ticks CHECK (ticks_remaining >= 0),
    CONSTRAINT valid_damage CHECK (damage_per_tick >= 0)
);

-- Create index for efficient querying by player
CREATE INDEX IF NOT EXISTS idx_status_effects_player ON player_status_effects(character_id);

-- Create index for background processor to find active effects
CREATE INDEX IF NOT EXISTS idx_status_effects_active ON player_status_effects(character_id, ticks_remaining) WHERE ticks_remaining > 0;
