import 'package:test_sa/models/timer_model.dart';
import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/modules/internal_audit_module/models/internal_audit_timer_model.dart';

class AuditFormModel {
  int? id;
  String? createdDate;
  int? requestId;
  String? debrief;
  DateTime? startTime;
  DateTime? endTime;
  double? totalHours;
  List<GenericAttachmentModel>? attachments;
  bool? isComplete;
  TimerModel? auditTimerModel = TimerModel();
  List<InternalAuditTimerModel>? auditTimers = [];
  TimerModel? auditTimePicker;
  List<TimerModel>? timerModelList = [];

  AuditFormModel(
      {this.id,
      this.requestId,
      this.debrief,
      this.startTime,
      this.endTime,
      this.totalHours,
      this.createdDate,
      this.attachments,
      this.isComplete,
      this.auditTimerModel,
      this.timerModelList,
      this.auditTimePicker,
      this.auditTimers});

  AuditFormModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    requestId = json['requestId'];
    debrief = json['debrief'];
    startTime = json['startTime'] != null ? DateTime.tryParse(json['startTime']) : null;
    endTime = json['endTime'] != null ? DateTime.tryParse(json['endTime']) : null;
    totalHours = json['totalHours']?.toDouble();
    if (json['attachments'] != null) {
      attachments = (json['attachments'] as List).map((e) => GenericAttachmentModel.fromInternalAuditJson(e)).toList();
    }
    isComplete = json['isComplete'];
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'requestId': requestId,
      'debrief': debrief,
      'startTime': startTime?.toIso8601String(),
      'endTime': endTime?.toIso8601String(),
      // 'auditTimer': auditTimers,
      'totalHours': totalHours,
      'attachments': attachments?.whereType<GenericAttachmentModel>().map((e) => e.toInternalAuditJson()).toList(),
      'isComplete': isComplete,
    };
  }
}
