class Team {
  const Team({
    required this.id,
    required this.name,
    required this.sport,
    this.logoUrl,
    this.youtubeConnected = false,
    this.planSlug = 'free',
    this.planName = 'Free',
    this.premiumActive = false,
    this.premiumFull = false,
    this.billingUrl,
    this.staffManageUrl,
    this.maxStaff = 2,
    this.staffUsed = 0,
    this.maxStaffTransmission,
    this.maxStaffRegia,
    this.staffTransmissionUsed = 0,
    this.staffRegiaUsed = 0,
    this.concurrentStreamsUsed = 0,
    this.concurrentStreamsLimit,
    this.recordingsEnabled = false,
    this.phoneDownloadEnabled = false,
    this.youtubeEnabled = false,
    this.clubName,
    this.staffRole,
    this.canStream = true,
    this.youtubeMode,
  });

  final String id;
  final String name;
  final String sport;
  final String? clubName;
  final String? staffRole;
  final bool canStream;
  final String? logoUrl;
  final bool youtubeConnected;
  final String planSlug;
  final String planName;
  final bool premiumActive;
  final bool premiumFull;
  final String? billingUrl;
  final String? staffManageUrl;
  final int maxStaff;
  final int staffUsed;
  final int? maxStaffTransmission;
  final int? maxStaffRegia;
  final int staffTransmissionUsed;
  final int staffRegiaUsed;
  final int concurrentStreamsUsed;
  final int? concurrentStreamsLimit;
  final bool recordingsEnabled;
  final bool phoneDownloadEnabled;
  final bool youtubeEnabled;
  final String? youtubeMode;

  bool get canUseYoutube => premiumFull && youtubeEnabled;
  bool get canUseRecordings => recordingsEnabled;
  bool get canDownloadOnPhone => phoneDownloadEnabled;

  String get staffLimitLabel {
    if (maxStaffTransmission == null) {
      return 'trasmissione illimitata';
    }
    return 'trasmissione $staffTransmissionUsed/$maxStaffTransmission';
  }

  factory Team.fromJson(Map<String, dynamic> json) {
    return Team(
      id: json['id'] as String,
      name: json['name'] as String,
      sport: json['sport'] as String? ?? 'volleyball',
      clubName: json['club_name'] as String?,
      staffRole: json['staff_role'] as String?,
      canStream: json['can_stream'] as bool? ?? true,
      logoUrl: json['logo_url'] as String?,
      youtubeConnected: json['youtube_connected'] as bool? ?? false,
      planSlug: json['plan_slug'] as String? ?? 'free',
      planName: json['plan_name'] as String? ?? 'Free',
      premiumActive: json['premium_active'] as bool? ?? false,
      premiumFull: json['premium_full'] as bool? ?? false,
      billingUrl: json['billing_url'] as String?,
      staffManageUrl: json['staff_manage_url'] as String?,
      maxStaff: json['max_staff'] as int? ?? 2,
      staffUsed: json['staff_used'] as int? ?? 0,
      maxStaffTransmission: json['max_staff_transmission'] as int?,
      maxStaffRegia: json['max_staff_regia'] as int?,
      staffTransmissionUsed: json['staff_transmission_used'] as int? ?? 0,
      staffRegiaUsed: json['staff_regia_used'] as int? ?? 0,
      concurrentStreamsUsed: json['concurrent_streams_used'] as int? ?? 0,
      concurrentStreamsLimit: json['concurrent_streams_limit'] as int?,
      recordingsEnabled: json['recordings_enabled'] as bool? ?? false,
      phoneDownloadEnabled: json['phone_download_enabled'] as bool? ?? false,
      youtubeEnabled: json['youtube_enabled'] as bool? ?? false,
      youtubeMode: json['youtube_mode'] as String?,
    );
  }
}
