import 'package:elektronika/app/core/utils/utils.dart';
import 'package:elektronika/app/data/models/models.dart';
import 'package:flutter/material.dart';

class SliderApi {
  static String className = 'SliderApi';

  static List<SliderModel> sliders = [];

  static Future<List<SliderModel>> get() async {
    final String fnName = 'get';

    if (sliders.isNotEmpty) return sliders;

    final List<SliderModel> list = [];

    try {
      debugPrint('class: $className, method: $fnName');

      const String path = Constants.BASE_URL + 'sliders';

      final response = await HttpUtil().get(
        path: path,
        queryParameters: {
          'locale': await getLocale(),
        },
      );

      for (final json in response['data']) {
        final SliderModel slider = SliderModel.fromJson(json);
        sliders.add(slider);
        list.add(slider);
      }

      return list;
    } catch (e) {
      debugPrint('ERROR: class: $className, method: $fnName, error: $e ');
      return list;
    }
  }
}
