import 'package:localization/localization.dart';

import '../../l10n/app_localizations.dart';

class HttpStatusManger {
  static String getStatusMessage({
    required int? status,
    required AppLocalizations subtitle,
    String? messageFor400,
    String? messageFor200,
  }) {
    if (status == null) {
      // no status code - code error no need for subtitle
      return "careful null status";
    }
    if (status == -1) {
      // client's request in process
      return subtitle.serverErrorMessage;
    }
    if (status == -2) {
      // client's request in process
      return subtitle.requestLockMessage;
    } else if (status >= 200 && status < 300) {
      // client's request was successfully received
      return messageFor200 ?? subtitle.successfulRequestMessage;
    } else if (status >= 400 && status < 500) {
      // client's request have error
      switch (status) {
        case 400:
          return messageFor400 ?? subtitle.failedRequestMessage;
        default:
          return subtitle.failedRequestMessage;
      }
    } else if (status >= 500) {
      // server error
      return subtitle.serverErrorMessage;
    } else {
      // no error match so return default error
      return subtitle.failedRequestMessage;
    }
  }
}
