/**
 * conflictTargetIdentity — facade for conflict target and effect identity.
 *
 * The runtime-backed concepts live in adjacent files named after the
 * concepts they own. This module keeps the analyzer import surface small.
 *
 * @module domain/services/strand/conflictTargetIdentity
 */
import ConflictTarget from "../../types/conflict/ConflictTarget.js";
import { normalizeConflictOp, receiptNameForOp, } from "./CanonicalConflictOp.js";
import ConflictEffectPayload, { ConflictEffectEnvelope, effectKey, normalizeNoteCodes, normalizeObservedDots, } from "./ConflictEffectPayload.js";
import ConflictTargetResolver from "./ConflictTargetResolver.js";
export { effectKey, normalizeConflictOp, normalizeNoteCodes, normalizeObservedDots, receiptNameForOp, };
export function buildEffectPayload(target, opType, payload) {
    return new ConflictEffectEnvelope({ target, opType, payload });
}
export function normalizeEffectPayload(canonOp, receiptOpType) {
    return ConflictEffectPayload.forOp(canonOp, receiptOpType);
}
export function buildTargetIdentity(canonOp, receiptTarget) {
    return ConflictTargetResolver.resolve(canonOp, receiptTarget);
}
export async function buildConflictTarget(context, { canonOp, receiptTarget }) {
    const targetIdentity = buildTargetIdentity(canonOp, receiptTarget);
    if (targetIdentity === null) {
        return null;
    }
    return new ConflictTarget({
        ...targetIdentity,
        targetDigest: await context.hash(targetIdentity),
    });
}
export async function buildEffectDigest(context, { target, receiptOpType, canonOp, }) {
    const effectPayload = normalizeEffectPayload(canonOp, receiptOpType);
    if (effectPayload === null) {
        return null;
    }
    return await context.hash(buildEffectPayload(target, receiptOpType, effectPayload));
}
