import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:mypoint_flutter_app/base/base_response_model.dart';
import 'package:mypoint_flutter_app/networking/restful_api_request.dart';
import 'package:mypoint_flutter_app/screen/create_pass/create_pass_screen.dart';
import 'package:mypoint_flutter_app/screen/create_pass/reset_create_password_repository.dart';
import '../../base/restful_api_viewmodel.dart';
import '../splash/splash_screen_viewmodel.dart';
import 'otp_viewmodel.dart';

class ForgotPassOTPRepository extends RestfulApiViewModel implements IOtpRepository {
  ForgotPassOTPRepository(this.phoneNumber, this.otpTtl);

  @override
  int otpTtl;

  @override
  String phoneNumber;

  @override
  Future<int?> resendOtp() {
    throw UnimplementedError();
  }

  @override
  Future<void> sendOtp() {
    throw UnimplementedError();
  }

  @override
  Future<BaseResponseModel<EmptyCodable>> verifyOtp(String otpCode) {
    showLoading();
    return client.otpVerifyForDoingNextEvent(phoneNumber, otpCode, "RESET_PASSWORD").then((value) {
      hideLoading();
      if (value.status == "success" || value.code == 200) {
        Get.off(() => CreatePasswordScreen(repository: ResetCreatePasswordRepository(phoneNumber)));
      }
      return value;
    });
  }
}