import 'package:clean/base/base_request.dart';
import 'package:clean/data/api/atmob_api.dart';
import 'package:clean/data/api/response/wallpaper_list_response.dart';
import 'package:clean/data/bean/wallpapers_bean.dart';
import 'package:clean/utils/http_handler.dart';
import 'package:get/get.dart';

class WallpaperRepository {
  WallpaperRepository._();

  Rxn<WallpaperListResponse> get wallpaper => _wallpaper;
  final Rxn<WallpaperListResponse> _wallpaper = Rxn<WallpaperListResponse>();
  final RxList<WallpapersBean> _wallpapersList = RxList<WallpapersBean>();
  RxList<WallpapersBean> get wallpapersList => _wallpapersList;

  Future<WallpaperListResponse> wallpaperList() {
    return atmobApi
        .wallpaperList(BaseRequest())
        .then(HttpHandler.handle(false))
        .then((data) {
      _wallpaper.value = data;
      _wallpapersList.value = data.wallpapers ?? [];
      return data;
    });
  }
}

final WallpaperRepository wallpaperRepository = WallpaperRepository._();
