import 'file.model.dart';

class CompanyModel {
  CompanyModel({
    required this.id,
    required this.createdAt,
    required this.updatedAt,
    required this.name,
    required this.isDelete,
    required this.files,
  });

  final int? id;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String? name;
  final int? isDelete;
  final List<FileModel> files;

  factory CompanyModel.fromJson(Map<String, dynamic> json) {
    return CompanyModel(
      id: json["id"],
      createdAt: DateTime.tryParse(json["createdAt"] ?? ""),
      updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""),
      name: json["name"],
      isDelete: json["isDelete"],
      files: json["files"] == null
          ? []
          : List<FileModel>.from(
              json["files"]!.map((x) => FileModel.fromJson(x))),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "createdAt": createdAt?.toIso8601String(),
        "updatedAt": updatedAt?.toIso8601String(),
        "name": name,
        "isDelete": isDelete,
        "files": files.map((x) => x?.toJson()).toList(),
      };
}
