import 'dart:convert';

import 'package:get/get.dart';
import 'package:siro_rider/constant/box_name.dart';
import 'package:siro_rider/constant/links.dart';
import 'package:siro_rider/controller/functions/crud.dart';
import 'package:siro_rider/main.dart';

class OrderHistoryController extends GetxController {
  List<dynamic> orderHistoryListPassenger = [];
  bool isloading = true;

  @override
  void onInit() {
    getOrderHistoryByPassenger();
    super.onInit();
  }

  Future getOrderHistoryByPassenger() async {
    var res = await CRUD().get(link: AppLink.getRides, payload: {
      'passenger_id': box.read(BoxName.passengerID).toString(),
    });
    if (res.toString() == 'failure') {
      // Get.snackbar('failure', 'message');
      isloading = false;
      update();
    } else {
      var jsonDecoded = jsonDecode(res);
      var rawData = jsonDecoded['data'] ?? jsonDecoded['message'];
      orderHistoryListPassenger = rawData is List ? rawData : [];
      isloading = false;
      update();
    }
  }
}
