require "rails_helper"

RSpec.describe Recording do
  let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
  let!(:team) { club.teams.create!(name: "Team", sport: "volleyball") }
  let!(:user) { User.create!(email: "coach@test.com", name: "Coach", password: "password123", role: "coach") }
  let!(:match) { team.matches.create!(opponent_name: "Rival", scheduled_at: 1.day.from_now) }
  let!(:session) do
    StreamSession.create!(
      match: match,
      user: user,
      platform: "matchlivetv",
      status: "ended",
      privacy_status: "public"
    )
  end

  it "is ready when status ready and not expired" do
    rec = described_class.create!(
      stream_session: session,
      team: team,
      status: "ready",
      expires_at: 1.day.from_now,
      storage_key: "teams/#{team.id}/sessions/#{session.id}/replay.mp4"
    )
    expect(rec).to be_ready
    expect(rec.replay_url).to include("/replay/#{session.id}")
  end

  it "exposes default title from match" do
    rec = described_class.create!(stream_session: session, team: team, status: "processing")
    expect(rec.title_or_default).to eq("Team vs Rival")
  end
end
