-- T0251: Create Track Database Model
-- Create table tracks with all required fields

-- Table tracks
CREATE TABLE IF NOT EXISTS tracks (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    title VARCHAR(255) NOT NULL,
    artist VARCHAR(255),
    album VARCHAR(255),
    duration INTEGER NOT NULL,
    genre VARCHAR(100),
    year INTEGER DEFAULT 0,
    file_path VARCHAR(500) NOT NULL,
    file_size BIGINT NOT NULL,
    format VARCHAR(10),
    bitrate INTEGER DEFAULT 0,
    sample_rate INTEGER DEFAULT 0,
    waveform_path VARCHAR(500),
    cover_art_path VARCHAR(500),
    is_public BOOLEAN DEFAULT TRUE,
    play_count BIGINT DEFAULT 0,
    like_count BIGINT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP
);

-- Indexes
CREATE INDEX IF NOT EXISTS idx_tracks_user_id ON tracks(user_id);
CREATE INDEX IF NOT EXISTS idx_tracks_is_public ON tracks(is_public);
CREATE INDEX IF NOT EXISTS idx_tracks_created_at ON tracks(created_at);

