import 'user.dart';

class Member {
  final String userId;
  final String orgId;
  final String role;
  final DateTime createdAt;
  final User user;

  const Member({
    required this.userId,
    required this.orgId,
    required this.role,
    required this.createdAt,
    required this.user,
  });

  factory Member.fromJson(Map<String, dynamic> json) {
    return Member(
      userId: json['UserID'] ?? json['userId'],
      orgId: json['OrgID'] ?? json['orgId'],
      role: json['Role'] ?? json['role'],
      createdAt: DateTime.parse(json['CreatedAt'] ?? json['createdAt']),
      user: User.fromJson(json['user']),
    );
  }
}

class Invitation {
  final String id;
  final String orgId;
  final String invitedBy;
  final String username;
  final String role;
  final DateTime createdAt;
  final DateTime expiresAt;
  final DateTime? acceptedAt;

  const Invitation({
    required this.id,
    required this.orgId,
    required this.invitedBy,
    required this.username,
    required this.role,
    required this.createdAt,
    required this.expiresAt,
    this.acceptedAt,
  });

  factory Invitation.fromJson(Map<String, dynamic> json) {
    return Invitation(
      id: json['id'],
      orgId: json['orgId'],
      invitedBy: json['invitedBy'],
      username: json['username'],
      role: json['role'],
      createdAt: DateTime.parse(json['createdAt']),
      expiresAt: DateTime.parse(json['expiresAt']),
      acceptedAt: json['acceptedAt'] != null
          ? DateTime.parse(json['acceptedAt'])
          : null,
    );
  }
}

class JoinRequest {
  final String id;
  final String orgId;
  final String userId;
  final String? inviteToken;
  final DateTime requestedAt;
  final String status;
  final User user;

  const JoinRequest({
    required this.id,
    required this.orgId,
    required this.userId,
    this.inviteToken,
    required this.requestedAt,
    required this.status,
    required this.user,
  });

  factory JoinRequest.fromJson(Map<String, dynamic> json) {
    return JoinRequest(
      id: json['ID'] ?? json['id'],
      orgId: json['OrgID'] ?? json['orgId'],
      userId: json['UserID'] ?? json['userId'],
      inviteToken: json['InviteToken'] ?? json['inviteToken'],
      requestedAt: DateTime.parse(json['RequestedAt'] ?? json['requestedAt']),
      status: json['Status'] ?? json['status'],
      user: User.fromJson(json['user']),
    );
  }
}
