import { AppObjectEntityRepo, generateUniqueID, } from "@vived/core";
import { Transform3D } from "../../Transform3D";
import { makeLandmarkEntity } from "./LandmarkEntity";
export class LandmarkRepo extends AppObjectEntityRepo {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getByID(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
    static addIfMissing(appObject) {
        const existing = appObject.getComponent(LandmarkRepo.type);
        if (existing) {
            return existing;
        }
        else {
            return makeLandmarkRepoEntity(appObject);
        }
    }
}
LandmarkRepo.type = "LANDMARK_REPO";
export function makeLandmarkRepoEntity(appObject) {
    return new LandmarkRepoImp(appObject);
}
class LandmarkRepoImp extends LandmarkRepo {
    get transform() {
        return this._transform;
    }
    applySurrogateTransform(transform) {
        this._transform = transform;
    }
    deleteLandmark(id) {
        const landmark = this.getForAppObject(id);
        if (!landmark)
            return;
        landmark.appObject.dispose();
        this.removeForAppObject(id);
    }
    constructor(appObject) {
        super(appObject, LandmarkRepo.type);
        this.createLandmark = (id) => {
            const idToUse = id ?? generateUniqueID();
            const landmark = this.landmarkFactory(idToUse);
            landmark.inRepo = this;
            this.add(landmark);
            return landmark;
        };
        this.landmarkFactory = (id) => {
            const ao = this.appObjects.getOrCreate(id);
            return makeLandmarkEntity(ao);
        };
        this._transform = Transform3D.addIfMissing(this.appObject);
    }
}
//# sourceMappingURL=LandmarkRepo.js.map