import 'package:boilerplate/data/data_source/remote/api_provider.dart';
import 'package:boilerplate/data/models/categories/get_categories_res_model.dart';
import 'package:boilerplate/data/repositories/base_repository.dart';
import 'package:injectable/injectable.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../models/categories/get_intellectual_type_res_model.dart';

@injectable
class CategoriesRepository extends BaseRepository {
  final ApiProvider _api;

  CategoriesRepository(this._api);

  Future<GetCategoriesResModel> getCategories() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    print("url => /api/category?lang=${prefs.getString('lang')}");
    final response =
        await _api.get('/api/category?lang=${prefs.getString('lang')}')
          ..responseHandler();
    print('resp => ${response.data}');

    return GetCategoriesResModel.fromJson(response.data);
  }

  Future<GetIntellectualTypesResModel> getIntellectualTypes() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    print("url => /api/intellectual-type?lang=${prefs.getString('lang')}");

    final response =
        await _api.get('/api/intellectual-type?lang=${prefs.getString('lang')}')
          ..responseHandler();

    return GetIntellectualTypesResModel.fromJson(response.data);
  }
}
