#pragma once

#include <string_view>
#include <string>
#include <optional>
#include <tl/expected.hpp>

#include "Address.hpp"

namespace tw::app {

/**
 * Parse an address string into a network address.
 *
 * Accepts "host:port" or a bare port number. Bare port uses 127.0.0.1.
 * Missing port defaults to 8080. Trims surrounding whitespace.
 * Validates the host with inet_pton and returns an error string
 * for non-IPv4 addresses or invalid ports.
 */
tl::expected<net::Address, std::string> parse_address(std::string_view text);

/**
 * Extract the --server argument value from the command line.
 *
 * Scans argv for --server and returns the following argument,
 * or nothing if the flag is absent or has no value.
 */
std::optional<std::string> server_arg(int argc, char** argv);

} // namespace tw::app
