// Generated by bynkc — do not edit by hand.
// commons demo

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

export type Quantity = number & { readonly __brand: "Quantity" };

export const Quantity = {
  of(value: number): Result<Quantity, ValidationError> {
    if (!Number.isInteger(value)) {
      return Err({ field: "Quantity", message: "must be an integer", value });
    }
    if (!(value >= 1 && value <= 100)) {
      return Err({ field: "Quantity", message: "must be in range [1, 100]", value });
    }
    return Ok(value as Quantity);
  },
  unsafe(value: number): Quantity {
    return value as Quantity;
  },
};

export function double(q: Quantity): number {
  return 2;
}

export function classify(n: number): number {
  const __r0 = n;
  if ((Number.isInteger(__r0) && (__r0 >= 1 && __r0 <= 100))) {
    const n = __r0 as Quantity;
    return double(n);
  } else {
    return 0;
  }
}

