"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LandmarkRepo = void 0;
exports.makeLandmarkRepoEntity = makeLandmarkRepoEntity;
const core_1 = require("@vived/core");
const Transform3D_1 = require("../../Transform3D");
const LandmarkEntity_1 = require("./LandmarkEntity");
class LandmarkRepo extends core_1.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);
        }
    }
}
exports.LandmarkRepo = LandmarkRepo;
LandmarkRepo.type = "LANDMARK_REPO";
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 ?? (0, core_1.generateUniqueID)();
            const landmark = this.landmarkFactory(idToUse);
            landmark.inRepo = this;
            this.add(landmark);
            return landmark;
        };
        this.landmarkFactory = (id) => {
            const ao = this.appObjects.getOrCreate(id);
            return (0, LandmarkEntity_1.makeLandmarkEntity)(ao);
        };
        this._transform = Transform3D_1.Transform3D.addIfMissing(this.appObject);
    }
}
//# sourceMappingURL=LandmarkRepo.js.map