/**
 * src/core/possibility.js — explicit possibilistic semantics.
 *
 * The single authoritative home for what the engine's operators MEAN in
 * possibility theory, in the spirit of Martin's plausibility contours and
 * Cella's FVN fusion (see zig-contour/spec/02-fusion.md).
 *
 * Possibility theory axioms the engine honors:
 *   - Possibility is maxitive: plausibility of a disjunction is the MAX of
 *     the plausibilities. This is why OR (union) is max and why max is the
 *     only operator that is already "valid and normalized" under arbitrary
 *     dependence (Cella §7.2).
 *   - A possibility value is a ranking, not a probability: 0.6 means "this
 *     is the least plausible option whose negation is not strictly more
 *     plausible" — it does NOT mean a 60% chance.
 *   - Conjunctive combination (AND) is the MIN, and the raw min is an
 *     UNVALIDIFIED ranking: the arbitrary-regime validification is
 *     min(1, K*gamma_min) (Prop 1 bound), and the pre-normalization
 *     suppression (conflict mass = 1 - gamma) must be surfaced, never
 *     silently dropped.
 *   - The PRODUCT operator (P(A)*(1-P(B)) in exclusion/defeasible) has no
 *     linear validification under arbitrary dependence (Cella Thm 4). Its
 *     outputs are ranking heuristics, never valid possibilities.
 *   - Interior OWA weights produce convex mixtures of plausibilities,
 *     which are not maxitive; they are scoring heuristics (nonMaxitive).
 *   - Reliability is NOT a possibility: it is a scalar confidence that
 *     adapts the fusion ranking (a fusion-step combiner), and must never
 *     be presented as, or conflated with, the plausibility value.
 */

export const OPERATOR_SEMANTICS = {
  identity: {
    class: 'disjunctive',
    label: 'a single source; the value is the source\'s plausibility',
    validity: 'preserves the source label',
    validified: false,
    nonMaxitive: false
  },
  max: {
    class: 'disjunctive',
    label: 'OR: plausibility of the union of options',
    validity: 'already valid and normalized under arbitrary dependence (Cella §7.2); fused label = weakest source label',
    validified: false,
    nonMaxitive: false
  },
  min: {
    class: 'conjunctive',
    label: 'AND: plausibility of the conjunction of options (unvalidified ranking)',
    validity: 'approximate at best; arbitrary-regime validification min(1, K*gamma_min) (Prop 1); conflict mass surfaced',
    validified: true,
    nonMaxitive: false
  },
  product: {
    class: 'heuristic',
    label: 'exclusion/defeasible: P(A)*(1-P(B)) style combination',
    validity: 'always heuristic — the product operator has no linear validification under arbitrary dependence (Cella Thm 4)',
    validified: false,
    nonMaxitive: false
  },
  owa: {
    class: 'heuristic',
    label: 'ordered weighted average with interior weights: convex mixture of sorted plausibilities',
    validity: 'always heuristic — convex mixtures are not maxitive',
    validified: false,
    nonMaxitive: true
  },
  mixed: {
    class: 'heuristic',
    label: 'multiple contributing rules with different operators',
    validity: 'heuristic if any contributor is heuristic or non-maxitive',
    validified: false,
    nonMaxitive: false
  }
};

export function operatorSemantics(operator) {
  return OPERATOR_SEMANTICS[operator] || OPERATOR_SEMANTICS.mixed;
}

/**
 * The decision semantics every consumer MUST respect:
 *   - possibility is a plausibility ranking; thresholds are ranking
 *     cutoffs, not probability bounds
 *   - a heuristic-labeled result carries no validity guarantee
 *   - reliability adapts the ranking; it does not measure plausibility
 *   - conflictMass is a debugging diagnostic, not a decision input
 */
export const DECISION_SEMANTICS = Object.freeze({
  possibilityIsRanking: true,
  reliabilityIsAdaptation: true,
  conflictMassIsDiagnostic: true,
  heuristicResultsCarryNoGuarantee: true
});
