import 'package:dio/dio.dart';
import 'package:frontend_eccp_mobile/app/core/constants/dio_constant.dart';
import 'package:frontend_eccp_mobile/app/core/network/api_endpoint.dart';
import 'package:frontend_eccp_mobile/app/core/network/dio_client.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_request.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_response.dart';
import 'package:injectable/injectable.dart';

@lazySingleton
class LoginRemoteDataSource {
  final Dio _dio = DioClient.getInstance();

  Future<LoginResponse> login(LoginRequest request) async {
    final response = await _dio.post<Map<String, dynamic>>(
      ApiEndpoint.login,
      data: request.toJson(),
      options: Options(
        extra: {DioExtraKey.noAuth: true},
      ),
    );

    final data = response.data;
    if (data == null) {
      throw Exception('EMPTY_RESPONSE');
    }

    return LoginResponse.fromJson(data);
  }
}
