// Generated by bynkc — do not edit by hand.
// adapter bynk

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "./runtime.js";

/**
 * A UUID in canonical 8-4-4-4-12 lowercase-hex form.
 */
export type Uuid = string & { readonly __brand: "Uuid" };

export const Uuid = {
  of(value: string): Result<Uuid, ValidationError> {
    if (!new RegExp("^" + "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + "$").test(value)) {
      return Err({ field: "Uuid", message: "must match /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/", value });
    }
    return Ok(value as Uuid);
  },
  unsafe(value: string): Uuid {
    return value as Uuid;
  },
};

/**
 * An HTTP request method.
 */
export type Method =
    { readonly tag: "Get" }
  | { readonly tag: "Post" }
  | { readonly tag: "Put" }
  | { readonly tag: "Delete" };

export const Method = {
  Get: { tag: "Get" } as Method,
  Post: { tag: "Post" } as Method,
  Put: { tag: "Put" } as Method,
  Delete: { tag: "Delete" } as Method,
};

/**
 * Why an outbound `Fetch.send` failed: a network error or a timeout.
 */
export type FetchError =
    { readonly tag: "Network" }
  | { readonly tag: "Timeout" };

export const FetchError = {
  Network: { tag: "Network" } as FetchError,
  Timeout: { tag: "Timeout" } as FetchError,
};

/**
 * An outbound HTTP request, as passed to `Fetch.send`.
 */
export interface Request {
  readonly method: Method;
  readonly url: string;
  readonly contentType: Option<string>;
  readonly authorization: Option<string>;
  readonly body: Option<string>;
}

export const Request = {
};

/**
 * An HTTP response: a status code and a body.
 */
export interface Response {
  readonly status: number;
  readonly body: string;
}

export const Response = {
};

/**
 * Reads the current wall-clock time, as Unix milliseconds.
 */
export interface Clock {
  now(): Promise<number>;
}

export const ClockToken: unique symbol = Symbol("Clock");

/**
 * A source of randomness — fresh UUIDs and bounded integers.
 */
export interface Random {
  uuid(): Promise<Uuid>;
  int(lo: number, hi: number): Promise<number>;
}

export const RandomToken: unique symbol = Symbol("Random");

/**
 * Structured logging at info and error levels.
 */
export interface Logger {
  info(msg: string): Promise<void>;
  error(msg: string): Promise<void>;
}

export const LoggerToken: unique symbol = Symbol("Logger");

/**
 * Performs outbound HTTP requests.
 */
export interface Fetch {
  send(req: Request): Promise<Result<Response, FetchError>>;
}

export const FetchToken: unique symbol = Symbol("Fetch");

/**
 * Reads named secrets from the platform's secret store.
 */
export interface Secrets {
  get(name: string): Promise<Option<string>>;
}

export const SecretsToken: unique symbol = Symbol("Secrets");

