import type { IiosPlatformPorts, SourceHandleResolution } from '@insignia/iios-contracts';

type MdmPort = IiosPlatformPorts['mdm'];

/**
 * Deterministic MDM fake. Defaults to UNRESOLVED (an unknown handle stays a
 * SourceHandle — no silent merge). Can be set to ambiguous or resolved.
 */
export class FakeMdm implements MdmPort {
  private resolution: SourceHandleResolution = {
    canonicalEntityId: undefined,
    confidence: 0,
    status: 'UNRESOLVED',
  };

  setResolution(r: Partial<SourceHandleResolution>): this {
    this.resolution = { ...this.resolution, ...r };
    return this;
  }

  ambiguous(confidence = 0.42): this {
    this.resolution = { canonicalEntityId: undefined, confidence, status: 'AMBIGUOUS' };
    return this;
  }

  resolved(canonicalEntityId: string, confidence = 0.99): this {
    this.resolution = { canonicalEntityId, confidence, status: 'RESOLVED' };
    return this;
  }

  async resolveSourceHandle(_input: unknown): Promise<SourceHandleResolution> {
    return this.resolution;
  }
}
