import '../../shared/models/approval_status.dart'; class OvertimeModel { final String id; final String applicationNo; final String applicantId; final String applicantName; final String deptId; final String deptName; final String otType; final String compensationType; final double? compLeaveRatio; final DateTime startTime; final DateTime endTime; final double netOtHours; final String reason; final String status; final String approvalInstanceId; final DateTime createTime; final DateTime updateTime; // 审批相关 final List approvalRecords; final List approvalChain; final String currentApproverId; const OvertimeModel({ required this.id, required this.applicationNo, required this.applicantId, required this.applicantName, required this.deptId, required this.deptName, required this.otType, required this.compensationType, this.compLeaveRatio, required this.startTime, required this.endTime, required this.netOtHours, required this.reason, this.status = 'draft', this.approvalInstanceId = '', required this.createTime, required this.updateTime, this.approvalRecords = const [], this.approvalChain = const [], this.currentApproverId = '', }); double get otHours => netOtHours; DateTime get otDate => startTime; factory OvertimeModel.fromJson(Map json) { return OvertimeModel( id: json['id'] as String, applicationNo: json['applicationNo'] as String? ?? '', applicantId: json['applicantId'] as String? ?? '', applicantName: json['applicantName'] as String? ?? '', deptId: json['deptId'] as String? ?? '', deptName: json['deptName'] as String? ?? '', otType: json['otType'] as String? ?? 'workday', compensationType: json['compensationType'] as String? ?? 'overtime_pay', compLeaveRatio: (json['compLeaveRatio'] as num?)?.toDouble(), startTime: DateTime.parse(json['startTime'] as String), endTime: DateTime.parse(json['endTime'] as String), netOtHours: (json['netOtHours'] as num?)?.toDouble() ?? 0.0, reason: json['reason'] as String? ?? '', status: json['status'] as String? ?? 'draft', approvalInstanceId: json['approvalInstanceId'] as String? ?? '', createTime: DateTime.parse(json['createTime'] as String), updateTime: DateTime.parse(json['updateTime'] as String), approvalRecords: (json['approvalRecords'] as List?) ?.map((e) => ApprovalRecord.fromJson(e as Map)) .toList() ?? [], approvalChain: (json['approvalChain'] as List?) ?.map((e) => e as String) .toList() ?? [], currentApproverId: json['currentApproverId'] as String? ?? '', ); } Map toJson() => { 'id': id, 'applicationNo': applicationNo, 'applicantId': applicantId, 'applicantName': applicantName, 'deptId': deptId, 'deptName': deptName, 'otType': otType, 'compensationType': compensationType, 'compLeaveRatio': compLeaveRatio, 'startTime': startTime.toIso8601String(), 'endTime': endTime.toIso8601String(), 'netOtHours': netOtHours, 'reason': reason, 'status': status, 'approvalInstanceId': approvalInstanceId, 'createTime': createTime.toIso8601String(), 'updateTime': updateTime.toIso8601String(), 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(), 'approvalChain': approvalChain, 'currentApproverId': currentApproverId, }; OvertimeModel copyWith({ String? id, String? applicationNo, String? applicantId, String? applicantName, String? deptId, String? deptName, String? otType, String? compensationType, double? compLeaveRatio, DateTime? startTime, DateTime? endTime, double? netOtHours, String? reason, String? status, String? approvalInstanceId, DateTime? createTime, DateTime? updateTime, List? approvalRecords, List? approvalChain, String? currentApproverId, }) { return OvertimeModel( id: id ?? this.id, applicationNo: applicationNo ?? this.applicationNo, applicantId: applicantId ?? this.applicantId, applicantName: applicantName ?? this.applicantName, deptId: deptId ?? this.deptId, deptName: deptName ?? this.deptName, otType: otType ?? this.otType, compensationType: compensationType ?? this.compensationType, compLeaveRatio: compLeaveRatio ?? this.compLeaveRatio, startTime: startTime ?? this.startTime, endTime: endTime ?? this.endTime, netOtHours: netOtHours ?? this.netOtHours, reason: reason ?? this.reason, status: status ?? this.status, approvalInstanceId: approvalInstanceId ?? this.approvalInstanceId, createTime: createTime ?? this.createTime, updateTime: updateTime ?? this.updateTime, approvalRecords: approvalRecords ?? this.approvalRecords, approvalChain: approvalChain ?? this.approvalChain, currentApproverId: currentApproverId ?? this.currentApproverId, ); } }