sailfork / t3code-github / .repos/ alchemy-effect/ examples/ cloudflare-domain/ packages/ domain/ src/ Customer/ RejectRegistration.command.ts

import * as Domain from "@alchemy.run/domain";
import * as Schema from "effect/Schema";
import { CustomerId } from "./Customer.id.ts";
import { Username } from "./Username.ts";

/** The registration failed; the customer may register again. */
export class RegistrationRejected extends Domain.Event("RegistrationRejected", {
  username: Username,
  reason: Schema.String,
}) {}

/** The username could not be claimed. Reports an outcome, so it never rejects. */
export class RejectRegistration extends Domain.Command("RejectRegistration", {
  target: CustomerId,
  input: { reason: Schema.String },
  events: [RegistrationRejected],
}) {}