import {NumberField, SchemaField} from "@common/data/fields.mjs";

/**
 * A specialized subclass of SchemaField that specifically deals with points.
 * This data structure accepts plain objects with {x, y} structure or PIXI.Point objects.
 */
export default class VFXPointField extends SchemaField {
  constructor(options={}, context={}) {
    super({
      x: new NumberField({ required: true, nullable: false}),
      y: new NumberField({ required: true, nullable: false})
    },
    {required: true, nullable: false, ...options}, context);
  }

  /* ---------------------------------------- */

  /** @override */
  _cast(value) {
    if (typeof value !== "object" || value === null) {
      return {};
    }
    if (foundry.utils.isPlainObject(value)) return value;
    return {x: value.x, y: value.y};
  }
}
