import 'dart:developer';

import 'package:dartz/dartz.dart';
import 'package:enaklo_pos/core/constants/variables.dart';
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart';
import 'package:http/http.dart' as http;

class PaymentMethodsRemoteDatasource {
  Future<Either<String, PaymentMethodsResponseModel>> getPaymentMethods() async {
    try {
      final authData = await AuthLocalDataSource().getAuthData();
      final response = await http.get(
        Uri.parse('${Variables.baseUrl}/api/payment-methods'),
        headers: {
          'Authorization': 'Bearer ${authData.token}',
          'Accept': 'application/json',
        },
      );
      
      log("Payment Methods Response Status: ${response.statusCode}");
      log("Payment Methods Response Body: ${response.body}");
      
      if (response.statusCode == 200) {
        return Right(PaymentMethodsResponseModel.fromJson(response.body));
      } else {
        return const Left('Failed to get payment methods');
      }
    } catch (e) {
      log("Error getting payment methods: $e");
      return Left('Error: $e');
    }
  }
} 