import BaseCombatant from"../../../common/documents/combatant.mjs";import ServerDocumentMixin from"../backend/server-document.mjs";export default class Combatant extends(ServerDocumentMixin(BaseCombatant)){async loadRelatedDocuments(){if(void 0===this.actor){const t=await db.Actor.get(this.actorId);this.actor=t||null}}static async _onCreateOperation(t,a,e){return await Combatant.#t(a),await Combatant.#a(a,e),super._onCreateOperation(t,a,e)}static async _onUpdateOperation(t,a,e){return await Combatant.#t(a),await Combatant.#a(a,e),super._onUpdateOperation(t,a,e)}static async _onDeleteOperation(t,a,e){return await Combatant.#t(a),super._onDeleteOperation(t,a,e)}static async#t(t){if("combatTurn"in t){const a=t.parent;if(t.combatTurn===a.turn)return;a.updateSource({turn:t.combatTurn}),await a.save({writeEmbedded:!1})}}static async#a(t,a){const e=t.parent;e.scene&&e.combatants.some((t=>t.sceneId&&t.sceneId!==e.scene))&&(e.updateSource({scene:null}),await e.save({writeEmbedded:!1}),db.DatabaseBackend.emit(e.documentName,"update",[{_id:e.id,scene:null}],{},a))}}