60 lines
1.4 KiB
Dart
60 lines
1.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
@immutable
|
|
class Department {
|
|
const Department({
|
|
required this.id,
|
|
required this.name,
|
|
this.code,
|
|
this.description,
|
|
this.isActive = true,
|
|
required this.updatedAt,
|
|
});
|
|
|
|
final String id;
|
|
final String name;
|
|
final String? code;
|
|
final String? description;
|
|
final bool isActive;
|
|
final DateTime updatedAt;
|
|
|
|
Department copyWith({
|
|
String? id,
|
|
String? name,
|
|
String? code,
|
|
String? description,
|
|
bool? isActive,
|
|
DateTime? updatedAt,
|
|
}) {
|
|
return Department(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
code: code ?? this.code,
|
|
description: description ?? this.description,
|
|
isActive: isActive ?? this.isActive,
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
);
|
|
}
|
|
|
|
factory Department.fromMap(Map<String, Object?> map) {
|
|
return Department(
|
|
id: map['id'] as String,
|
|
name: map['name'] as String? ?? '-',
|
|
code: map['code'] as String?,
|
|
description: map['description'] as String?,
|
|
isActive: (map['is_active'] as int? ?? 1) == 1,
|
|
updatedAt: DateTime.parse(map['updated_at'] as String),
|
|
);
|
|
}
|
|
|
|
Map<String, Object?> toMap() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'code': code,
|
|
'description': description,
|
|
'is_active': isActive ? 1 : 0,
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
};
|
|
}
|
|
}
|