import 'package:flutter/material.dart';

class AlternativeService {
  int? serviceID;
  String? serviceName;
  bool? isSelected;

  AlternativeService(
      {this.serviceID, this.serviceName, this.isSelected = false});

  AlternativeService.fromJson(Map<String, dynamic> json) {
    serviceID = json['ServicID'];
    serviceName = json['ServiceName'];
    isSelected = false;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['ServicID'] = this.serviceID;
    data['ServiceName'] = this.serviceName;
    return data;
  }
}

class AlternativeServicesList with ChangeNotifier {
  List<AlternativeService> _alternativeServicesList = [];

  getServicesList() {
    return _alternativeServicesList;
  }

  setServicesList(List<AlternativeService> alternativeServicesList) {
    this._alternativeServicesList = alternativeServicesList;
    notifyListeners();
  }

  setSelected(AlternativeService service, bool? isSelected) {
    List<AlternativeService> alternativeService = _alternativeServicesList
        .where((element) => service.serviceID == element.serviceID)
        .toList();

    alternativeService[0].isSelected = isSelected;
    notifyListeners();
  }
}
