// Extension to add members property to Team
import '../models/team_member.dart';

extension TeamMembersExtension on Team {
  List<String> members(List<TeamMember> allMembers) {
    return allMembers
        .where((m) => m.teamId == id)
        .map((m) => m.userId)
        .toList();
  }
}

class Team {
  Team({
    required this.id,
    required this.name,
    required this.leaderId,
    required this.officeIds,
    required this.createdAt,
  });

  final String id;
  final String name;
  final String leaderId;
  final List<String> officeIds;
  final DateTime createdAt;

  factory Team.fromMap(Map<String, dynamic> map) {
    return Team(
      id: map['id'] as String,
      name: map['name'] as String? ?? '',
      leaderId: map['leader_id'] as String? ?? '',
      officeIds:
          (map['office_ids'] as List?)?.map((e) => e.toString()).toList() ??
          <String>[],
      createdAt: DateTime.parse(map['created_at'] as String),
    );
  }
}
