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 username,
    required String password,
    // required String company_id,
    // required String regional_id,
  }) async {
    final param = {
      "username": username,
      "password": password,
      // "company_id": company_id,
      // "regional_id": regional_id

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

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

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

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

  Future<String> changePassword({
    required String token,
    required String current_password,
    required String new_password,
    required String password_confirmation,
  }) async {
    final param = {
      "token": token,
      "current_password": current_password,
      "new_password": new_password,
      "password_confirmation": password_confirmation
    };

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

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