enum ConnectionStatus { pending, approved, rejected }

extension ConnectionStatusX on ConnectionStatus {
  String get value => name;
  String get label {
    switch (this) {
      case ConnectionStatus.pending:
        return 'Bekliyor';
      case ConnectionStatus.approved:
        return 'Onaylı';
      case ConnectionStatus.rejected:
        return 'Reddedildi';
    }
  }
}

class Connection {
  const Connection({
    required this.id,
    required this.clinicTenantId,
    required this.labTenantId,
    required this.status,
    this.clinicName,
    this.labName,
    this.dateCreated,
  });

  final String id;
  final String clinicTenantId;
  final String labTenantId;
  final ConnectionStatus status;
  final String? clinicName;
  final String? labName;
  final String? dateCreated;

  factory Connection.fromJson(Map<String, dynamic> j) {
    final expand = j['expand'] as Map<String, dynamic>?;
    final clinicExp = expand?['clinic_tenant_id'] as Map<String, dynamic>?;
    final labExp = expand?['lab_tenant_id'] as Map<String, dynamic>?;
    return Connection(
      id: j['id'] as String,
      clinicTenantId: j['clinic_tenant_id'] as String,
      labTenantId: j['lab_tenant_id'] as String,
      status: ConnectionStatus.values.firstWhere(
        (e) => e.value == j['status'],
        orElse: () => ConnectionStatus.pending,
      ),
      clinicName: clinicExp?['company_name'] as String?,
      labName: labExp?['company_name'] as String?,
      dateCreated: j['created'] as String?,
    );
  }
}
