import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
import 'package:syncrow_app/features/auth/model/signup_model.dart';
import 'package:syncrow_app/features/auth/model/token.dart';
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
import 'package:syncrow_app/services/api/http_service.dart';

class AuthenticationAPI {
  static Future<Map<String, dynamic>> verifyPassCode(
      {required Map<String, dynamic> body}) async {
    final response = await HTTPService().post(
        path: ApiEndpoints.verifyOtp,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) => json);
    return response;
  }

  static Future<Token> loginWithEmail(
      {required LoginWithEmailModel model}) async {
    final response = await HTTPService().post(
        path: ApiEndpoints.login,
        body: model.toJson(),
        showServerMessage: false,
        expectedResponseModel: (json) => Token.fromJson(json['data']));
    return response;
  }

  static Future<bool> signUp({
    required SignUpModel model,
    required String accessToken,
  }) async {
    final response = await HTTPService().post(
        path: ApiEndpoints.signUp,
        body: model.toJson(),
        showServerMessage: false,
        accessToken: accessToken,
        expectedResponseModel: (json) => json['statusCode'] == 201);
    return response;
  }

  static Future<Map<String, dynamic>> sendOtp(
      {required Map<String, dynamic> body}) async {
    final response = await HTTPService().post(
        path: ApiEndpoints.sendOtp,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json['data'];
        });
    return response;
  }

  static Future<Map<String, dynamic>> forgetPassword({
    required String otpCode,
    required String email,
    required String password,
  }) async {
    Map<String, dynamic> params = {
      "email": email,
      "password": password,
      "otpCode": otpCode
    };
    final response = await HTTPService().post(
        path: ApiEndpoints.forgetPassword,
        body: params,
        showServerMessage: false,
        expectedResponseModel: (json) => json['data']);
    return response;
  }

  static Future<Map<String, dynamic>> fetchClientToken({
    required String clientId,
    required String clientSecret,
  }) async {
    final response = await HTTPService().post(
      path: ApiEndpoints.clientLogin,
      body: {
        'clientId': clientId,
        'clientSecret': clientSecret,
      },
      showServerMessage: false,
      expectedResponseModel: (json) => json['data'],
    );
    return response;
  }
}
