softplayer-web/lib/helpers/providers/common.dart

53 lines
1.6 KiB
Dart
Raw Normal View History

2024-05-02 17:09:44 +00:00
import 'package:softplayer_dart_proto/environments/environments_v1.pbenum.dart';
import 'package:softplayer_web/helpers/providers/hetzner.dart';
2024-04-30 15:31:53 +00:00
abstract class Provider {
2024-05-02 17:09:44 +00:00
String getServerLocation(String serverLocation);
String rawServerLocation(String serverLocation);
String defaultLocation();
String getProviderName();
String rawProviderName();
}
class ProviderHelper {
String getServerType(String serverType) {
if (serverType == ServerType.SERVER_TYPE_STARTER.toString()) {
return "Starter";
} else if (serverType == ServerType.SERVER_TYPE_REGULAR.toString()) {
return "Regular";
} else if (serverType == ServerType.SERVER_TYPE_PLUS.toString()) {
return "Plus";
} else if (serverType == ServerType.SERVER_TYPE_PRO.toString()) {
return "Pro";
} else if (serverType == ServerType.SERVER_TYPE_CUSTOM.toString()) {
throw 'Custom server type is not yet supported';
} else {
throw 'Unknown server type';
}
}
String rawServerType(String serverType) {
if (serverType == "Starter") {
return ServerType.SERVER_TYPE_STARTER.toString();
} else if (serverType == "Regular") {
return ServerType.SERVER_TYPE_REGULAR.toString();
} else if (serverType == "Plus") {
return ServerType.SERVER_TYPE_PLUS.toString();
} else if (serverType == "Pro") {
return ServerType.SERVER_TYPE_PRO.toString();
} else {
throw 'Unknown server type';
}
}
Hetzner getProvider(String provider) {
switch (provider) {
case "hetzner" || "PROVIDER_HETZNER":
return Hetzner();
default:
throw "unknown prodiver";
}
}
}