-- T0356: Create Playback Analytics Database Model
-- Migration pour créer la table playback_analytics

CREATE TABLE playback_analytics (
    id BIGSERIAL PRIMARY KEY,
    track_id BIGINT NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    play_time INTEGER NOT NULL DEFAULT 0,
    pause_count INTEGER NOT NULL DEFAULT 0,
    seek_count INTEGER NOT NULL DEFAULT 0,
    completion_rate DECIMAL(5,2) NOT NULL DEFAULT 0,
    started_at TIMESTAMP NOT NULL,
    ended_at TIMESTAMP,
    created_at TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_playback_analytics_track_id ON playback_analytics(track_id);
CREATE INDEX idx_playback_analytics_user_id ON playback_analytics(user_id);
CREATE INDEX idx_playback_analytics_created_at ON playback_analytics(created_at);

