-- T0306: Create Track Sharing System Database Model
-- Create table track_shares with all required fields

-- Table track_shares
CREATE TABLE IF NOT EXISTS track_shares (
    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,
    share_token VARCHAR(255) UNIQUE NOT NULL,
    permissions VARCHAR(50) DEFAULT 'read',
    expires_at TIMESTAMP,
    access_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_track_shares_track_id ON track_shares(track_id);
CREATE INDEX IF NOT EXISTS idx_track_shares_user_id ON track_shares(user_id);
CREATE INDEX IF NOT EXISTS idx_track_shares_share_token ON track_shares(share_token);
CREATE INDEX IF NOT EXISTS idx_track_shares_deleted_at ON track_shares(deleted_at);

