import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/service/property_service.dart';

class PropertyRepository {
  List<Property>? _properties;

  Future<List<Property>?> getDBProperties() async {
    this._properties = await PropertyApi().getProperties();
    return this._properties;
  }

  List<Property>? getProperties() {
    return this._properties;
  }

  Property? getPropertyByName(String name) {
    Property? property;
    if (_properties == null) {
      _properties = Cache().getProperties();
    }
    if (_properties != null) {
      this._properties!.forEach((element) {
        if (name == element.propertyName) {
          property = element;
        }
      });
    }
    return property;
  }
}
