import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/networking/restful_api_request.dart';
import 'package:mypoint_flutter_app/screen/login/login_screen.dart';
import '../../base/base_response_model.dart';
import '../../base/restful_api_viewmodel.dart';
import '../splash/splash_screen_viewmodel.dart';

abstract class ICreatePasswordRepository {
  late String phoneNumber;
  Future<BaseResponseModel<EmptyCodable>> setPassword(String password);
}

class SignUpCreatePasswordRepository extends RestfulApiViewModel implements ICreatePasswordRepository {
  @override
  late String phoneNumber;

  SignUpCreatePasswordRepository(this.phoneNumber);

  @override
  Future<BaseResponseModel<EmptyCodable>> setPassword(String password) async {
    showLoading();
    return client.signup(phoneNumber, password).then((value) {
      hideLoading();
      if (value.status == "success" || value.code == 200) {
        print("signup success");
        Get.off(() => LoginScreen(phoneNumber: phoneNumber));
      }
      return value;
    });
  }
}
