// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // // SPDX-License-Identifier: MIT const Client = @This(); const std = @import("std"); const options = @import("options"); const UUID = @import("uuid").UUID; const Check = @import("Check.zig"); io: std.Io, rng_impl: std.Random.IoSource, alloc: std.mem.Allocator, client: std.http.Client, user_agent: []const u8, base_url: []const u8, base_uri: std.Uri, pub fn init(io: std.Io, alloc: std.mem.Allocator, base_url: []const u8) !Client { const user_agent = try std.fmt.allocPrint(alloc, "healthchecks/{f}", .{options.version}); errdefer alloc.free(user_agent); const base_url_copy = try alloc.dupe(u8, base_url); errdefer alloc.free(base_url_copy); const uri: std.Uri = try .parse(base_url_copy); return .{ .io = io, .rng_impl = .{ .io = io }, .alloc = alloc, .client = .{ .io = io, .allocator = alloc, }, .user_agent = user_agent, .base_url = base_url_copy, .base_uri = uri, }; } pub fn deinit(self: *Client) void { self.client.deinit(); self.alloc.free(self.user_agent); self.alloc.free(self.base_url); } pub fn allocator(self: *Client) std.mem.Allocator { return self.alloc; } pub fn rng(self: *Client) std.Random { return self.rng_impl.interface(); } pub fn check(self: *Client, id: UUID) Check { return .init(self, id); }