import 'tenant.dart';

class TenantInvite {
  const TenantInvite({
    required this.id,
    required this.tenantId,
    required this.email,
    required this.jobRole,
    required this.token,
    required this.expiresAt,
    required this.status,
    required this.invitedById,
  });

  final String id;
  final String tenantId;
  final String email;
  final TenantRole jobRole;
  final String token;
  final DateTime expiresAt;
  final String status; // pending | accepted | expired
  final String invitedById;

  bool get isPending => status == 'pending';
  bool get isExpired => status == 'expired' || expiresAt.isBefore(DateTime.now());

  factory TenantInvite.fromJson(Map<String, dynamic> j) => TenantInvite(
        id: j['id'] as String,
        tenantId: j['tenant_id'] as String,
        email: j['email'] as String,
        jobRole: TenantMembership.parseRole(j['job_role'] as String),
        token: j['token'] as String,
        expiresAt: DateTime.parse(j['expires_at'] as String),
        status: j['status'] as String,
        invitedById: j['invited_by'] as String,
      );
}
