import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:kmobile/data/models/user.dart';

class UserService {
  final Dio _dio;
  UserService(this._dio);

  Future<List<User>> getUserDetails() async {
    try {
      final response = await _dio.get('/api/customer');
      if (response.statusCode == 200) {
        log('Response: ${response.data}');
        return (response.data as List)
            .map((user) => User.fromJson(user))
            .toList();
      } else {
        throw Exception('Failed to load customer details');
      }
    } on DioException catch (e) {
      if (kDebugMode) {
        print(e.toString());
      }
      throw Exception('Network error: ${e.message}');
    } catch (e) {
      throw Exception('Unexpected error: ${e.toString()}');
    }
  }
}
