66 lines
1.8 KiB
Dart
66 lines
1.8 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
|
|
class ReminderDefaultModel extends Equatable {
|
|
final String? id;
|
|
final String companyId;
|
|
final String staffId;
|
|
final int minutesBefore;
|
|
final String channel; // 'push' o 'email'
|
|
|
|
const ReminderDefaultModel({
|
|
this.id,
|
|
required this.companyId,
|
|
required this.staffId,
|
|
required this.minutesBefore,
|
|
required this.channel,
|
|
});
|
|
|
|
ReminderDefaultModel copyWith({
|
|
String? id,
|
|
String? companyId,
|
|
String? staffId,
|
|
int? minutesBefore,
|
|
String? channel,
|
|
}) {
|
|
return ReminderDefaultModel(
|
|
id: id ?? this.id,
|
|
companyId: companyId ?? this.companyId,
|
|
staffId: staffId ?? this.staffId,
|
|
minutesBefore: minutesBefore ?? this.minutesBefore,
|
|
channel: channel ?? this.channel,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
if (id != null) 'id': id,
|
|
'company_id': companyId,
|
|
'staff_id': staffId,
|
|
'minutes_before': minutesBefore,
|
|
'channel': channel,
|
|
};
|
|
}
|
|
|
|
factory ReminderDefaultModel.fromMap(Map<String, dynamic> map) {
|
|
return ReminderDefaultModel(
|
|
id: map['id'] as String?,
|
|
companyId: map['company_id'] as String,
|
|
staffId: map['staff_id'] as String,
|
|
minutesBefore: map['minutes_before'] as int,
|
|
channel: map['channel'] as String,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [id, companyId, staffId, minutesBefore, channel];
|
|
|
|
// Helper per la UI: formatta i minuti in qualcosa di leggibile (es. "1 ora prima")
|
|
String get friendlyTime {
|
|
if (minutesBefore < 60) return '$minutesBefore minuti prima';
|
|
if (minutesBefore == 60) return '1 ora prima';
|
|
if (minutesBefore < 1440) return '${minutesBefore ~/ 60} ore prima';
|
|
if (minutesBefore == 1440) return '1 giorno prima';
|
|
return '${minutesBefore ~/ 1440} giorni prima';
|
|
}
|
|
}
|