import 'package:sk_base_mobile/constants/enum.dart';
import 'package:sk_base_mobile/models/file.model.dart';
import 'package:sk_base_mobile/models/index.dart';
import 'package:sk_base_mobile/models/inventory.model.dart';
import 'package:sk_base_mobile/models/product.model.dart';
import 'package:sk_base_mobile/models/project.model.dart';

class InventoryInOutModel {
  InventoryInOutModel({
    required this.id,
    required this.createdAt,
    required this.updatedAt,
    required this.inventoryNumber,
    required this.productId,
    required this.inOrOut,
    required this.time,
    required this.quantity,
    required this.unitPrice,
    required this.amount,
    required this.agent,
    required this.issuanceNumber,
    required this.remark,
    required this.projectId,
    required this.isDelete,
    required this.files,
    required this.project,
    required this.product,
    this.inventory,
  });

  final int? id;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String? inventoryNumber;
  final int? productId;
  final int? inOrOut;
  final DateTime? time;
  final int? quantity;
  final String? unitPrice;
  final String? amount;
  final String? agent;
  final dynamic issuanceNumber;
  final String? remark;
  final int? projectId;
  final int? isDelete;
  final List<FileModel> files;
  final ProjectModel? project;
  final ProductModel? product;
  final InventoryModel? inventory;
  factory InventoryInOutModel.fromJson(Map<String, dynamic> json) {
    return InventoryInOutModel(
      id: json["id"],
      createdAt: DateTime.tryParse(json["createdAt"] ?? ""),
      updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""),
      inventoryNumber: json["inventoryNumber"],
      productId: json["productId"],
      inOrOut: json["inOrOut"],
      time: DateTime.tryParse(json["time"] ?? ""),
      quantity: json["quantity"],
      unitPrice: json["unitPrice"],
      amount: json["amount"],
      agent: json["agent"],
      issuanceNumber: json["issuanceNumber"],
      remark: json["remark"],
      projectId: json["projectId"],
      isDelete: json["isDelete"],
      files: json["files"] == null
          ? []
          : List<FileModel>.from(
              json["files"]!.map((x) => FileModel.fromJson(x))),
      project: json["project"] == null
          ? null
          : ProjectModel.fromJson(json["project"]),
      product: json["product"] == null
          ? null
          : ProductModel.fromJson(json["product"]),
      inventory: json['inventory'] == null
          ? null
          : InventoryModel.fromJson(json["inventory"]),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "createdAt": createdAt?.toIso8601String(),
        "updatedAt": updatedAt?.toIso8601String(),
        "inventoryNumber": inventoryNumber,
        "productId": productId,
        "inOrOut": inOrOut,
        "time": time,
        "quantity": quantity,
        "unitPrice": unitPrice,
        "amount": amount,
        "agent": agent,
        "issuanceNumber": issuanceNumber,
        "remark": remark,
        "projectId": projectId,
        "isDelete": isDelete,
        "files": files.map((x) => x).toList(),
        "project": project?.toJson(),
        "product": product?.toJson(),
        "inventory": inventory?.toJson(),
      };
}
