require "rails_helper"

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

  before do
    ClubMembership.create!(club: club, user: owner, role: "owner")
  end

  it "sends email and marks notified" do
    recording = Recording.create!(
      stream_session: session,
      team: team,
      status: "ready",
      expires_at: 10.days.from_now,
      storage_key: "key"
    )

    expect {
      described_class.new(recording).call
    }.to change { ActionMailer::Base.deliveries.size }.by(1)

    expect(recording.reload.ready_notified_at).to be_present
  end
end
