class Account { final int id; final String name; final String type; final String currency; final double initialBalance; final double appBalance; final bool isActive; Account({ required this.id, required this.name, required this.type, required this.currency, required this.initialBalance, required this.appBalance, required this.isActive, }); factory Account.fromJson(Map json) { return Account( id: json['id'] as int, name: json['name'] as String, type: json['type'] as String, currency: json['currency'] as String? ?? 'MAD', initialBalance: (json['initial_balance'] as num? ?? 0).toDouble(), appBalance: (json['app_balance'] as num? ?? 0).toDouble(), isActive: json['is_active'] is int ? (json['is_active'] as int) == 1 : json['is_active'] as bool? ?? true, ); } Map toJson() { return { 'id': id, 'name': name, 'type': type, 'currency': currency, 'initial_balance': initialBalance, 'app_balance': appBalance, 'is_active': isActive, }; } Map toDbMap() { return { 'id': id, 'name': name, 'type': type, 'currency': currency, 'initial_balance': initialBalance, 'app_balance': appBalance, 'is_active': isActive ? 1 : 0, 'updated_at': DateTime.now().toIso8601String(), }; } factory Account.fromDbMap(Map map) { return Account( id: map['id'] as int, name: map['name'] as String, type: map['type'] as String, currency: map['currency'] as String? ?? 'MAD', initialBalance: (map['initial_balance'] as num? ?? 0).toDouble(), appBalance: (map['app_balance'] as num? ?? 0).toDouble(), isActive: (map['is_active'] as int? ?? 1) == 1, ); } Account copyWith({ int? id, String? name, String? type, String? currency, double? initialBalance, double? appBalance, bool? isActive, }) { return Account( id: id ?? this.id, name: name ?? this.name, type: type ?? this.type, currency: currency ?? this.currency, initialBalance: initialBalance ?? this.initialBalance, appBalance: appBalance ?? this.appBalance, isActive: isActive ?? this.isActive, ); } }