import { AppObjectEntity, MemoizedNumber, Quaternion, Vector3 } from "@vived/core";
import { Hideable } from "../../Hideable";
import { LabelEntity } from "../../Label";
import { OverlayColor } from "../../OverlayColor";
import { makeSelectable } from "../../Selection";
import { Transform3D } from "../../Transform3D";
export const LANDMARK_MINIMUM_SIZE = 0.1;
export const LANDMARK_MAXIMUM_SIZE = 2;
export class LandmarkEntity extends AppObjectEntity {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
}
LandmarkEntity.type = "LANDMARK";
export function makeLandmarkEntity(appObject) {
    const landmark = new LandmarkImp(appObject);
    return landmark;
}
class LandmarkImp extends LandmarkEntity {
    get id() {
        return this.appObject.id;
    }
    get label() {
        return this._label;
    }
    get transform() {
        return this._transform;
    }
    get hideable() {
        return this._hideable;
    }
    get overlayColor() {
        return this._overlayColor;
    }
    get selectable() {
        return this._selectable;
    }
    get size() {
        return this.memoizedSize.val;
    }
    set size(val) {
        this.memoizedSize.val = val;
    }
    get position() {
        return this._transform.localPosition;
    }
    set position(p) {
        this._transform.localPosition = p;
    }
    get rotation() {
        return this._transform.localRotation;
    }
    set rotation(r) {
        this._transform.localRotation = r;
    }
    set inRepo(val) {
        this._inRepo = val;
        this.transform.parent = val?.transform;
    }
    get inRepo() {
        return this._inRepo;
    }
    get parentID() {
        return this._inRepo ? this._inRepo.appObject.id : "";
    }
    get data() {
        return {
            id: this.appObject.id,
            parentID: this.parentID,
            position: this.position.dto,
            rotation: this.rotation.dto,
            size: this.memoizedSize.val,
            label: this._label.custom,
            defaultLabel: this._label.default,
            color: this._overlayColor.overlayColor,
        };
    }
    set data(dto) {
        this.rotation = Quaternion.FromDTO(dto.rotation);
        this.position = Vector3.FromDTO(dto.position);
        this.memoizedSize.val = dto.size;
        this._label.custom = dto.label;
        this._label.default = dto.defaultLabel;
        this._overlayColor.overlayColor = dto.color;
    }
    dispose() {
        super.dispose();
        this._label.removeChangeObserver(this.notifyOnChange);
        this._transform.removeChangeObserver(this.notifyOnChange);
        this._hideable.removeChangeObserver(this.notifyOnChange);
        this._overlayColor.removeChangeObserver(this.notifyOnChange);
        this._selectable.removeChangeObserver(this.notifyOnChange);
        this._label.dispose();
        this._transform.dispose();
        this._hideable.dispose();
        this._overlayColor.dispose();
        this._selectable.dispose();
        if (this._inRepo) {
            this._inRepo.removeForAppObject(this.appObject.id);
        }
    }
    constructor(appObject) {
        super(appObject, LandmarkEntity.type);
        this.memoizedSize = new MemoizedNumber(0, this.notifyOnChange);
        this._label = LabelEntity.addIfMissing(appObject);
        this._label.addChangeObserver(this.notifyOnChange);
        this._transform = Transform3D.addIfMissing(appObject);
        this._transform.addChangeObserver(this.notifyOnChange);
        this._hideable = Hideable.addIfMissing(appObject);
        this._hideable.addChangeObserver(this.notifyOnChange);
        this._overlayColor = OverlayColor.addIfMissing(appObject);
        this._overlayColor.addChangeObserver(this.notifyOnChange);
        this._selectable = makeSelectable(appObject);
        this._selectable.addChangeObserver(this.notifyOnChange);
    }
}
//# sourceMappingURL=LandmarkEntity.js.map