import { DirectiveSchema, JSExpression } from '../types';
import { Node } from './Node';

// v-[name]:[arg].[modifiers]="value"
export class Directive {
  arg?: string;
  modifiers?: string[];
  value?: JSExpression;
  extend?: Record<string, any>;
  constructor(public owner: Node, scheam: DirectiveSchema) {
    const { arg, modifiers, value, extend } = scheam;
    this.arg = arg;
    this.modifiers = modifiers;
    this.value = value;
    this.extend = extend;
  }
  update(scheam: DirectiveSchema) {
    const { arg, modifiers, value, extend } = scheam;
    if (arg) {
      this.arg = arg;
    }

    if (modifiers) {
      this.modifiers = modifiers;
    }

    if (value) {
      this.value = value;
    }

    if (extend) {
      this.extend = extend;
    }
  }
  getSchema() {
    const { arg, modifiers, value, extend } = this;
    return {
      arg,
      modifiers,
      value,
      extend
    };
  }
}
