import { BaseNode } from './BaseNode.js';

/**
 * AST node for direct evidence statements
 * Represents: owns(user, doc)
 */
export class DirectEvidenceNode extends BaseNode {
  constructor(location = null) {
    super('DirectEvidence', location);
    this.predicate = null; // PredicateNode
    this.negated = false;
  }

  /**
   * Set the predicate for this direct evidence
   * @param {PredicateNode} predicate - Predicate to set
   */
  setPredicate(predicate) {
    this.predicate = predicate;
    this.addChild(predicate);
  }

  /**
   * Set whether this evidence is negated
   * @param {boolean} negated - Whether evidence is negated
   */
  setNegated(negated) {
    this.negated = negated;
  }

  /**
   * Check if this evidence is negated
   * @returns {boolean} True if negated
   */
  isNegated() {
    return this.negated;
  }

  /**
   * Get the predicate name
   * @returns {string|null} Predicate name or null
   */
  getPredicateName() {
    return this.predicate ? this.predicate.name : null;
  }

  /**
   * Get the predicate arguments
   * @returns {ExpressionNode[]} Predicate arguments
   */
  getArguments() {
    return this.predicate ? this.predicate.arguments : [];
  }

  /**
   * Validate the direct evidence
   * @returns {string[]} Array of error messages
   */
  validate() {
    const errors = [];

    // Validate predicate
    if (!this.predicate) {
      errors.push('Direct evidence must have a predicate');
    } else {
      const predErrors = this.predicate.validate ? this.predicate.validate() : [];
      errors.push(...predErrors);
    }

    return errors;
  }

  toString() {
    const negStr = this.negated ? 'NOT ' : '';
    const predStr = this.predicate ? this.predicate.toString() : 'null';
    return `DirectEvidence(${negStr}${predStr})`;
  }
}
