import 'package:didvan/models/ai/bot_assistants_model.dart';
import 'package:didvan/models/enums.dart';
import 'package:didvan/providers/core.dart';

import 'package:didvan/services/network/request.dart';
import 'package:didvan/services/network/request_helper.dart';

class BotAssistantsState extends CoreProvier {
  List<BotAssistants> myAssistants = [];
  List<BotAssistants> globalAssistants = [];
  bool isMyAssistants = true;

  void getGlobalAssissmant() async {
    globalAssistants.clear();

    appState = AppState.busy;
    update();
    final service = RequestService(
      RequestHelper.usersAssistants(personal: false),
    );
    await service.httpGet();
    if (service.isSuccess) {
      final BotAssistantsModel toolsModel =
          BotAssistantsModel.fromJson(service.result);

      globalAssistants.addAll(toolsModel.botAssistants ?? []);

      appState = AppState.idle;
      update();
      return;
    }
    appState = AppState.failed;
    update();
  }

  void getMyAssissmant() async {
    myAssistants.clear();
    appState = AppState.busy;
    update();
    final service = RequestService(
      RequestHelper.usersAssistants(personal: true),
    );
    await service.httpGet();
    if (service.isSuccess) {
      final BotAssistantsModel toolsModel =
          BotAssistantsModel.fromJson(service.result);

      myAssistants.addAll(toolsModel.botAssistants ?? []);

      appState = AppState.idle;
      update();
      return;
    }
    appState = AppState.failed;
    update();
  }
}
