// lib/core/networks/positions_api.dart

import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'api_client.dart';
import '../../features/admin/tabs/REQUESTS/requests_main_tab.dart'; // Keep your relative path as needed

class PositionsApi {
  // ==========================================
  // FETCH ALL POSITIONS
  // ==========================================
  static Future<List<Map<String, dynamic>>> getPositions() async {
    try {
      final List<dynamic> data = await ApiClient.getPositions();
      return data.map((e) => Map<String, dynamic>.from(e)).toList();
    } catch (e) {
      debugPrint('Error fetching positions: $e');
      return [];
    }
  }

  // ==========================================
  // CREATE POSITION
  // ==========================================
  static Future<bool> createPosition(Map<String, dynamic> positionData) async {
    try {
      await ApiClient.createPosition(positionData);
      return true;
    } catch (e) {
      debugPrint('Create Position Network Error: $e');
      return false;
    }
  }

  // ==========================================
  // UPDATE POSITION
  // ==========================================
  static Future<bool> updatePosition(int id, Map<String, dynamic> positionData) async {
    try {
      await ApiClient.updatePosition(id, positionData);
      return true;
    } catch (e) {
      debugPrint('Update Position Network Error: $e');
      return false;
    }
  }

  // ==========================================
  // DELETE POSITION
  // ==========================================
  static Future<bool> deletePosition(int id) async {
    try {
      await ApiClient.deletePosition(id);
      return true;
    } catch (e) {
      debugPrint('Delete Position Network Error: $e');
      return false;
    }
  }
}