import 'dart:convert';
import 'dart:typed_data';

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

class LoanInstallationPullOutFormModel {
  String? snNo;
  DateTime? date;
  Uint8List? signature;
  List<GenericAttachmentModel>? loanAttachment;
  TimerModel? timerModel = TimerModel();
  DateTime? startTime;
  DateTime? endTime;
  double? totalHours;
  int? loanId;
  String? userId;
  int? loanStatusId;

  LoanInstallationPullOutFormModel({
    this.loanAttachment,
    this.timerModel,
    this.snNo,
    this.signature,
    this.date,
    this.startTime,
    this.endTime,
    this.totalHours,
    this.loanId,
    this.loanStatusId,
    this.userId,
  });

  Map<String, dynamic> toJson() {
    return {
      'serialNumber': snNo,
      'installationDate': date?.toIso8601String(),
      'pulloutDate': date?.toIso8601String(),
      "loanAttachments": loanAttachment != null ? loanAttachment!.map((v) => v.toLoanJson()).toList() : [],
      "installationSignature": signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature!)}" : null,
      "signature": signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature!)}" : null,
      "pulloutSignature": signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature!)}" : null,
      'startTime': startTime?.toIso8601String(),
      'endTime': endTime?.toIso8601String(),
      'totalHours': totalHours,
      'loanId': loanId,
      'loanStatusId': loanStatusId,
      'userId': userId,
      'isFromMobile': true,
    };
  }

  Map<String, dynamic> toInstallationJson() {
    return {
      'serialNumber': snNo,
      'installationDate': date?.toIso8601String(),
      "loanAttachments": loanAttachment != null ? loanAttachment!.map((v) => v.toLoanJson()).toList() : [],
      "installationSignature": signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature!)}" : null,
      'startTime': startTime?.toIso8601String(),
      'endTime': endTime?.toIso8601String(),
      'totalHours': totalHours,
      'loanId': loanId,
      'loanStatusId': loanStatusId,
      'userId': userId,
      'isFromMobile': true,
    };
  }

  Map<String, dynamic> toPulloutJson() {
    return {
      'serialNumber': snNo,
      'pulloutDate': date?.toIso8601String(),
      "loanAttachments": loanAttachment != null ? loanAttachment!.map((v) => v.toLoanJson()).toList() : [],
      "pulloutSignature": signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature!)}" : null,
      'startTime': startTime?.toIso8601String(),
      'endTime': endTime?.toIso8601String(),
      'totalHours': totalHours,
      'loanId': loanId,
      'loanStatusId': loanStatusId,
      'userId': userId,
      'isFromMobile': true,
    };
  }
}
