const std = @import("std"); pub const fleet = @import("fleet.zig"); const st = @import("root.zig"); const http = st.http; const Client = http.Client; const Response = st.http.Response; const models = st.models; const Wrapper = models.Wrapper; const Query = models.Query; pub fn account(client: *Client) !Response(models.accounts.AccountWrapper) { return client.request( Wrapper(models.accounts.AccountWrapper), "/my/account", .{}, .{ .auth = .agent }, ); } pub fn info(client: *Client) !http.RawResponse(models.Info) { return client.request( models.Info, "/", .{}, .{ .auth = .none }, ); } pub const agent = struct { pub fn register( client: *Client, symbol: []const u8, faction: models.factions.Symbol, ) !Response(models.agents.Register) { return client.postW( models.agents.Register, "/register", .{}, .{ .symbol = symbol, .faction = faction }, .account, ); } pub fn list(client: *Client, opts: Query) !Response([]models.agents.Agent) { return client.getW( []models.agents.Agent, "/agents{f}", .{opts}, .agent, ); } pub fn get(client: *Client, symbol: []const u8) !Response(models.agents.Agent) { return client.getW( models.agents.Agent, "/agents/{s}", .{symbol}, .agent, ); } pub fn own(client: *Client) !Response(models.agents.Agent) { return client.getW( models.agents.Agent, "/my/agent", .{}, .agent, ); } }; pub const system = struct { const Symbol = models.systems.Symbol; pub fn get(client: *Client, symbol: Symbol.System) !Response(models.systems.System) { return client.getW( models.systems.System, "/systems/{f}", .{symbol}, .agent, ); } pub fn list(client: *Client, opts: Query) !Response([]models.systems.System) { return client.getW( []models.systems.System, "/systems{f}", .{opts}, .agent, ); } pub fn waypoint( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Waypoint) { return client.getW( models.systems.Waypoint, "/systems/{f}/waypoints/{f}", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); } pub const WaypointsFilter = struct { type: ?models.systems.Waypoint.Type = null, traits: []models.systems.Waypoint.Trait = &.{}, pub fn format(this: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { if (this.type) |ty| { try writer.print("&type={s}", .{@tagName(ty)}); } if (this.traits.len > 0) { for (this.traits) |trait| { try writer.print("&traits={s}", .{@tagName(trait)}); } } } }; pub fn waypoints( client: *Client, symbol: Symbol.System, filter: WaypointsFilter, opts: Query, ) !Response([]models.systems.Waypoint) { return client.getW( []models.systems.Waypoint, "/systems/{f}/waypoints{f}{f}", .{ symbol, opts, filter }, .agent, ); } pub fn construction( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Construction) { return client.getW( models.systems.Construction, "/systems/{f}/waypoints/{f}/construction", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); } pub const SupplyConstruction = struct { shipSymbol: []const u8, tradeSymbol: models.inventory.AllItems.Combined, units: u64, pub const Response = struct { construction: models.systems.ConstructionSite, cargo: models.inventory.Cargo, }; }; pub fn supplyConstruction( client: *Client, waypoint_symbol: Symbol.Waypoint, supply: SupplyConstruction, ) !Response(SupplyConstruction.Response) { return client.postW( SupplyConstruction.Response, "/systems/{f}/waypoints/{f}/supply-construction", .{ waypoint_symbol.system, waypoint_symbol }, supply, .agent, ); } pub fn market( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Market) { return client.getW( models.systems.Market, "/systems/{f}/waypoints/{f}/market", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); } pub fn shipyard( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Shipyard) { return client.getW( models.systems.Shipyard, "/systems/{f}/waypoints/{f}/shipyard", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); } };