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

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

  Future<List<AliasesModel>> getAliases({required String token}) async {
    final param = {"token": token};
    final service = "${Constant.baseUrl}authchange/getuseraliases";
    final resp = await post(param: param, service: service);

    var aliases = <AliasesModel>[];

    if (resp['status'] == 'OK') {
      resp['data'].forEach((v) {
        aliases.add(AliasesModel.fromJson(v));
      });
    } else {
      
    }

    return aliases;
  }

  Future<String> requestToken({
    required String token,
    required String userID,
    required String username,
    required String targetUrl,
  }) async {
    final param = {
      "token": token,
      "userID": userID,
      "username": username,
      "targetUrl": targetUrl
    };

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

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