import 'package:test_sa/models/lookup.dart';

class CostCenterModel {
  int? id;
  int? assetDeliveryExternalDetailId;
  Lookup? costCenter;
  String? acceptedBy;
  String? costCenterName;
  DateTime? acceptanceDate;
  String? acceptedByEmail;
  String? acceptedBySignature;
  double? quantity;

  CostCenterModel({
    this.id,
    this.assetDeliveryExternalDetailId,
    this.costCenter,
    this.acceptedBy,
    this.costCenterName,
    this.acceptanceDate,
    this.acceptedByEmail,
    this.acceptedBySignature,
    this.quantity,
  });

  CostCenterModel.fromJson(Map<String, dynamic> json) {
    costCenterName = json['costCenter'] ?? json['costCenterName'];
    acceptanceDate = json['acceptanceDate'] != null ? DateTime.tryParse(json['acceptanceDate']) : null;
    acceptedBySignature = json['acceptedBySignature'];
    acceptedByEmail = json['acceptedByEmail'];
    quantity = json['qty'] ?? json['costCenterQty'];
    acceptedBy = json['acceptedBy'];
    costCenter = json['costCenter'] != null ? Lookup(name: json['costCenter']) : null;
    id = json['id'] ?? json['costCenterId'];
    assetDeliveryExternalDetailId = json['assetDeliveryExternalDetailId'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};

    data['id'] = id ?? 0;
    data['qty'] = quantity;
    data['costCenter'] = costCenterName;
    return data;
  }

  Map<String, dynamic> toEndUserAcceptanceFormJson() {
    final Map<String, dynamic> data = {};
    data['assetDeliveryExternalDeliveryId'] = assetDeliveryExternalDetailId;
    data['costCenterName'] = costCenterName;
    data['acceptedBy'] = acceptedBy;
    data['acceptanceDate'] = acceptanceDate?.toIso8601String();
    data['acceptedByEmail'] = acceptedByEmail;
    data['acceptedBySignature'] = acceptedBySignature;
    return data;
  }
}
