CREATE TABLE broadcast_notifications (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    title VARCHAR(64),
    message VARCHAR(256),
    button_label VARCHAR(32),
    button_url VARCHAR,
    frequency INTEGER DEFAULT 0,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE broadcast_notification_views (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id varchar(64) NOT NULL REFERENCES users(id),
    broadcast_notification_id varchar(64) NOT NULL REFERENCES broadcast_notifications(id)  ON DELETE CASCADE,
    view_count INTEGER DEFAULT 0,
    active_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX user_broadcast_idx ON broadcast_notification_views(user_id, broadcast_notification_id);
