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

class TaskType  extends Base{
  final int? id;
  final String? typeName;
  final RelatedTo? relatedTo;
  final bool? linkWithMultiAssets;
  final List<TaskTypeRole>? taskTypeRoles;
  final bool? isInstallation;
  final bool? isRecallAndAlert;

  TaskType({
    this.id,
    this.typeName,
    this.relatedTo,
    this.linkWithMultiAssets,
    this.taskTypeRoles,
    this.isInstallation,
    this.isRecallAndAlert,
  }): super(name: typeName, identifier: id?.toString());

  factory TaskType.fromJson(Map<String, dynamic> json) {
    return TaskType(
      id: json['id'] as int?,
      typeName: json['typeName'] as String?,
      relatedTo: json['relatedTo'] != null
          ? RelatedTo.fromJson(json['relatedTo'])
          : null,
      linkWithMultiAssets: json['linkWithMultiAssets'] as bool?,
      taskTypeRoles: (json['taskTypeRoles'] as List<dynamic>?)
          ?.map((e) => TaskTypeRole.fromJson(e))
          .toList(),
      isInstallation: json['isInstallation'] as bool?,
      isRecallAndAlert: json['isRecallAndAlert'] as bool?,
    );
  }
}

class RelatedTo {
  final int? id;
  final String? name;
  final int? value;

  RelatedTo({
    this.id,
    this.name,
    this.value,
  });

  factory RelatedTo.fromJson(Map<String, dynamic> json) {
    return RelatedTo(
      id: json['id'] as int?,
      name: json['name'] as String?,
      value: json['value'] as int?,
    );
  }
}

class TaskTypeRole {
  final String? roleId;
  final String? roleName;
  final String? roleValue;

  TaskTypeRole({
    this.roleId,
    this.roleName,
    this.roleValue,
  });

  factory TaskTypeRole.fromJson(Map<String, dynamic> json) {
    return TaskTypeRole(
      roleId: json['roleId'] as String?,
      roleName: json['roleName'] as String?,
      roleValue: json['roleValue'] as String?,
    );
  }
}
