require "rails_helper"

RSpec.describe Recordings::ClubStats 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")
  end

  it "aggregates ready replays" do
    Recording.create!(
      stream_session: session,
      team: team,
      status: "ready",
      byte_size: 100.megabytes,
      expires_at: 3.days.from_now,
      storage_key: "a"
    )
    stats = described_class.new(club).call
    expect(stats[:available_count]).to eq(1)
    expect(stats[:expiring_soon_count]).to eq(1)
    expect(stats[:total_bytes]).to eq(100.megabytes)
  end
end
