import 'dart:developer';

import 'package:test_sa/extensions/enum_extensions.dart';
import 'package:test_sa/models/enums/demo_request_step.dart';
import 'package:test_sa/models/enums/work_order_next_step.dart';

import 'base.dart';

//Need to change this to accept generic enum model..
class Lookup extends Base {
  int? id; // Now nullable
  int? value; // Now nullable
  WorkOrderNextStepEnum? workOrderNextStepEnum; // Now nullable
  AssetDeliveryStageEnum? assetDeliveryStageEnum; // Now nullable
  DemoRequestStepEnum? demoRequestStepEnum; // Now nullable
  String? name; // Now nullable

  Lookup({this.id, this.value, this.name, this.workOrderNextStepEnum, this.assetDeliveryStageEnum, this.demoRequestStepEnum}) : super(identifier: id?.toString(), name: name);

  @override
  bool operator ==(Object other) => identical(this, other) || other is Lookup && ((value != null && value == other.value) || (id != null && id == other.id));

  @override
  int get hashCode => id.hashCode ^ value.hashCode; // Use XOR for hash code combination

  Map<String, dynamic> toJson() {
    // Return a Map instead of calling a function
    return {"id": id, "name": name, "value": value};
  }

  static Lookup? fromStatus(Lookup? old) {
    // Now accepts nullable Lookup and returns nullable Lookup
    if (old == null) return null;
    return Lookup(
      name: old.name,
      id: old.id,
      value: old.value,
    );
  }

  // CreatedBy.fromJson(dynamic json) {
  //   userId = json['userId'] ?? '';
  //   userName = json['userName'] ?? '';
  // }

  factory Lookup.fromJson(Map<String, dynamic>? parsedJson) {
    if (parsedJson == null) return Lookup();
    return Lookup(
      name: parsedJson["name"],
      workOrderNextStepEnum: parsedJson["value"] == null ? null : (parsedJson["value"] as int).toWorkOrderNextStepEnum(),
      assetDeliveryStageEnum: parsedJson["value"] == null ? null : (parsedJson["value"] as int).toAssetDeliveryStageEnum(),
      demoRequestStepEnum: parsedJson["value"] == null ? null : (parsedJson["value"] as int).toDemoRequestStepEnum(),
      id: parsedJson["id"],
      value: parsedJson["value"],
    );
  }
}
