import '../app/constant.dart';
import '../model/auth_model.dart';
import 'base_repository.dart';

class AuthRepository extends BaseRepository {
  AuthRepository({required super.dio});

  Future<AuthModel> login({
    required String email,
    // required String dokterId,
    required String password,
  }) async {
    final param = {
      "email": email,
      // "doctor_id": dokterId,
      "password": password

      // "username": "alhadad1",
      // "doctor_id": "2891",
      // "password": "3"
    };
    // final service = "${Constant.baseUrlDevone}xauth/login";
    final service = "${Constant.baseUrlDevone}auth/login";
    print('url login $service');
    final resp = await post(param: param, service: service);
    final result = AuthModel(
      token: resp["data"]["token"],
      model: AuthDoctorModel.fromJson(resp["data"]["user"]),
    );
    return result;
  }

  Future<String> logout({
    required String M_UserID,
    required String M_UserUsername,
  }) async {
    final param = {
      "M_UserID": M_UserID,
      "M_UserUsername": M_UserUsername
      // "username": "alhadad",
      // "doctor_id": "3101210841",
      // "password": "riau123"
    };

    final service = "${Constant.baseUrlDevone}auth/logout";
    print('url login $service');
    final resp = await post(param: param, service: service);

    if (resp["status"] == "OK") {
      return resp['status'];
    } else {
      return resp['message'];
    }
  }

  Future<String> change_password({
    required String token,
    required String M_UserID,
    required String username,
    required String doctor_id,
    required String new_password,
    required String confirm_password,
  }) async {
    final param = {
      "token": token,
      "M_UserID": M_UserID,
      "username": username,
      "doctor_id": doctor_id,
      "new_password": new_password,
      "confirm_password": confirm_password

      // "username": "alhadad",
      // "doctor_id": "3101210841",
      // "password": "riau123"
    };

    final service = "${Constant.baseUrlDevone}auth/change_password";
    final resp = await post(param: param, service: service);

    // final result = AuthModel(
    //   token: resp["data"]["token"],
    //   model: AuthDoctorModel.fromJson(resp["data"]["user"]),
    // );
    // return result;
    
    if (resp["status"] == "OK") {
      return resp['message'];
    } else {
      return resp['message'];
    }
  }
}
