import type { MemberType, Scalar } from "@typespec/compiler";
import type {
  CustomMutationClasses,
  MutationEngine,
  MutationFor,
  MutationHalfEdge,
  MutationOptions,
} from "./mutation-engine.js";
import { Mutation, type MutationInfo } from "./mutation.js";

export abstract class ScalarMutation<
  TOptions extends MutationOptions,
  TCustomMutations extends CustomMutationClasses,
  TEngine extends MutationEngine<TCustomMutations> = MutationEngine<TCustomMutations>,
> extends Mutation<Scalar, TCustomMutations, TOptions, TEngine> {
  readonly kind = "Scalar";
  baseScalar?: MutationFor<TCustomMutations, "Scalar">;

  constructor(
    engine: TEngine,
    sourceType: Scalar,
    referenceTypes: MemberType[],
    options: TOptions,
    info: MutationInfo,
  ) {
    super(engine, sourceType, referenceTypes, options, info);
  }

  protected mutateBaseScalar() {
    if (this.sourceType.baseScalar) {
      this.baseScalar = this.engine.mutate(
        this.sourceType.baseScalar,
        this.options,
        this.startBaseScalarEdge(),
      );
    }
  }

  protected abstract startBaseScalarEdge(): MutationHalfEdge;

  mutate() {
    this.mutateBaseScalar();
  }
}
