def METHOD_NAME(self, name: t.Optional[str] = None) -> GatewayConfig:
    if isinstance(self.gateways, dict):
        if name is None:
            if self.default_gateway:
                if self.default_gateway not in self.gateways:
                    raise ConfigError(f"Missing gateway with name '{self.default_gateway}'")
                return self.gateways[self.default_gateway]
            if "" in self.gateways:
                return self.gateways[""]
            return next(iter(self.gateways.values()))
        if name not in self.gateways:
            raise ConfigError(f"Missing gateway with name '{name}'.")
        return self.gateways[name]
    else:
        if name is not None:
            raise ConfigError(
                "Gateway name is not supported when only one gateway is configured."
            )
        return self.gateways