require "rails_helper"

RSpec.describe Recordings::FinalizeSession 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",
      ended_at: Time.current
    )
  end

  before do
    load Rails.root.join("db/seeds/plans.rb")
    Billing::AssignPlan.call(club: club, plan_slug: "premium_light")
  end

  it "creates processing recording with retention" do
    rec = described_class.new(session).call
    expect(rec.status).to eq("processing")
    expect(rec.privacy_status).to eq("public")
    expect(rec.expires_at).to be > 29.days.from_now
  end

  it "skips free plan" do
    Billing::AssignPlan.call(club: club, plan_slug: "free")
    expect(described_class.new(session).call).to be_nil
  end
end
