import '../../shared/models/approval_status.dart'; class VehicleModel { final String id; final String applicationNo; final String applicantId; final String applicantName; final String deptId; final String deptName; final String vehicleType; final String purpose; final DateTime startTime; final DateTime endTime; final String origin; final String destination; final int passengerCount; final String driver; final String licensePlate; final double estimatedMileage; final double estimatedCost; final String reason; final String status; final String currentApproverId; final List approvalChain; final DateTime createTime; final DateTime updateTime; final List approvalRecords; const VehicleModel({ required this.id, required this.applicationNo, required this.applicantId, required this.applicantName, required this.deptId, required this.deptName, this.vehicleType = '轿车', required this.purpose, required this.startTime, required this.endTime, required this.origin, required this.destination, this.passengerCount = 1, this.driver = '', this.licensePlate = '', this.estimatedMileage = 0.0, this.estimatedCost = 0.0, required this.reason, this.status = 'draft', this.currentApproverId = '', this.approvalChain = const [], required this.createTime, required this.updateTime, this.approvalRecords = const [], }); factory VehicleModel.fromJson(Map json) { return VehicleModel( 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? ?? '', vehicleType: json['vehicleType'] as String? ?? '轿车', purpose: json['purpose'] as String? ?? '', startTime: DateTime.parse(json['startTime'] as String), endTime: DateTime.parse(json['endTime'] as String), origin: json['origin'] as String? ?? '', destination: json['destination'] as String? ?? '', passengerCount: json['passengerCount'] as int? ?? 1, driver: json['driver'] as String? ?? '', licensePlate: json['licensePlate'] as String? ?? '', estimatedMileage: (json['estimatedMileage'] as num?)?.toDouble() ?? 0.0, estimatedCost: (json['estimatedCost'] as num?)?.toDouble() ?? 0.0, reason: json['reason'] as String? ?? '', status: json['status'] as String? ?? 'draft', currentApproverId: json['currentApproverId'] as String? ?? '', approvalChain: (json['approvalChain'] as List?) ?.map((e) => e as String) .toList() ?? [], 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() ?? [], ); } Map toJson() => { 'id': id, 'applicationNo': applicationNo, 'applicantId': applicantId, 'applicantName': applicantName, 'deptId': deptId, 'deptName': deptName, 'vehicleType': vehicleType, 'purpose': purpose, 'startTime': startTime.toIso8601String(), 'endTime': endTime.toIso8601String(), 'origin': origin, 'destination': destination, 'passengerCount': passengerCount, 'driver': driver, 'licensePlate': licensePlate, 'estimatedMileage': estimatedMileage, 'estimatedCost': estimatedCost, 'reason': reason, 'status': status, 'currentApproverId': currentApproverId, 'approvalChain': approvalChain, 'createTime': createTime.toIso8601String(), 'updateTime': updateTime.toIso8601String(), 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(), }; VehicleModel copyWith({ String? id, String? applicationNo, String? applicantId, String? applicantName, String? deptId, String? deptName, String? vehicleType, String? purpose, DateTime? startTime, DateTime? endTime, String? origin, String? destination, int? passengerCount, String? driver, String? licensePlate, double? estimatedMileage, double? estimatedCost, String? reason, String? status, String? currentApproverId, List? approvalChain, DateTime? createTime, DateTime? updateTime, List? approvalRecords, }) { return VehicleModel( id: id ?? this.id, applicationNo: applicationNo ?? this.applicationNo, applicantId: applicantId ?? this.applicantId, applicantName: applicantName ?? this.applicantName, deptId: deptId ?? this.deptId, deptName: deptName ?? this.deptName, vehicleType: vehicleType ?? this.vehicleType, purpose: purpose ?? this.purpose, startTime: startTime ?? this.startTime, endTime: endTime ?? this.endTime, origin: origin ?? this.origin, destination: destination ?? this.destination, passengerCount: passengerCount ?? this.passengerCount, driver: driver ?? this.driver, licensePlate: licensePlate ?? this.licensePlate, estimatedMileage: estimatedMileage ?? this.estimatedMileage, estimatedCost: estimatedCost ?? this.estimatedCost, reason: reason ?? this.reason, status: status ?? this.status, currentApproverId: currentApproverId ?? this.currentApproverId, approvalChain: approvalChain ?? this.approvalChain, createTime: createTime ?? this.createTime, updateTime: updateTime ?? this.updateTime, approvalRecords: approvalRecords ?? this.approvalRecords, ); } }