import 'package:didvan/models/enums.dart';
import 'package:didvan/models/overview_data.dart';
import 'package:didvan/providers/core.dart';
import 'package:didvan/services/network/request.dart';
import 'package:didvan/services/network/request_helper.dart';

class HashtagState extends CoreProvier {
  final List<OverviewData> items = [];

  late final int id;
  int page = 1;
  int lastPage = 1;

  Future<void> getTagItems({required int page}) async {
    this.page = page;
    if (this.page == 1) {
      appState = AppState.busy;
    }
    final service = RequestService(RequestHelper.tagV2(
      ids: [id],
      limit: 15,
      page: page,
    ));
    await service.httpGet();
    if (service.isSuccess) {
      lastPage = service.result['lastPage'];
      final contents = service.result['contents'];

      for (var i = 0; i < contents.length; i++) {
        items.add(OverviewData.fromJson(contents[i]));
      }
      appState = AppState.idle;
      return;
    }
    appState = AppState.failed;
  }
}
