// ignore_for_file: null_check_always_fails

import 'package:special_equipment_flutter/dio/entity_factory.dart';

class BaseListModel<T> {
  bool? success;
  String? errorCode;
  String? msg;
  List<T>? body;

  BaseListModel({this.success, this.errorCode, this.msg, this.body});

  factory BaseListModel.fromJson(json) {
    List<T> mBody = [];
    if (json["body"] != null && json["body"]["body"] != null) {
      for (var element in (json["body"]["body"] as List)) {
        mBody.add(EntityFactory.generateOBJ<T>(element));
      }
    }

    if (json["Data"] != null) {
      return BaseListModel(
          success: json["success"],
          errorCode: json["errorCode"],
          msg: json["msg"],
          body: mBody);
    } else {
      return BaseListModel(
        success: json["success"],
        errorCode: json["errorCode"],
        msg: json["msg"],
        body: null!,
      );
    }
  }
}
