h-1.flutter.0/lib/models/staff_model.dart
2026-03-04 14:55:40 +09:00

78 lines
1.9 KiB
Dart

import 'package:flutter/foundation.dart';
@immutable
class StaffMember {
const StaffMember({
required this.id,
required this.name,
this.email,
this.tel,
this.role,
this.departmentId,
this.permissionLevel,
this.isActive = true,
required this.updatedAt,
});
final String id;
final String name;
final String? email;
final String? tel;
final String? role;
final String? departmentId;
final String? permissionLevel;
final bool isActive;
final DateTime updatedAt;
StaffMember copyWith({
String? id,
String? name,
String? email,
String? tel,
String? role,
String? departmentId,
String? permissionLevel,
bool? isActive,
DateTime? updatedAt,
}) {
return StaffMember(
id: id ?? this.id,
name: name ?? this.name,
email: email ?? this.email,
tel: tel ?? this.tel,
role: role ?? this.role,
departmentId: departmentId ?? this.departmentId,
permissionLevel: permissionLevel ?? this.permissionLevel,
isActive: isActive ?? this.isActive,
updatedAt: updatedAt ?? this.updatedAt,
);
}
factory StaffMember.fromMap(Map<String, Object?> map) {
return StaffMember(
id: map['id'] as String,
name: map['name'] as String? ?? '-',
email: map['email'] as String?,
tel: map['tel'] as String?,
role: map['role'] as String?,
departmentId: map['department_id'] as String?,
permissionLevel: map['permission_level'] 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,
'email': email,
'tel': tel,
'role': role,
'department_id': departmentId,
'permission_level': permissionLevel,
'is_active': isActive ? 1 : 0,
'updated_at': updatedAt.toIso8601String(),
};
}
}