import{deepClone,mergeObject,parseUuid}from"../../common/utils/helpers.mjs";export async function fromUuid(e,{invalid:t=!1}={}){let s;const{collection:i,documentId:n,documentType:d,embedded:o}=parseUuid(e);for(s="CompendiumDocument"===i.name&&"Folder"===d?await i.getFolder(n,{strict:!0,dropInvalidEmbedded:!0}):await i.get(n,{strict:!0,dropInvalidEmbedded:!0});s&&o.length>1;){const[e,i]=o.splice(0,2);s=s.getEmbeddedDocument(e,i,{strict:!0,invalid:t}),s instanceof foundry.documents.BaseToken&&o.length&&await s.loadRelatedDocuments()}return s||null}export function tagModelStats(e,{changes:t,user:s,modifiedTime:i,recursive:n}={}){if(!e.schema.has("_stats"))return;const d=e._stats,{release:o,game:a}=global,m=!1===n?deepClone(d):{};m.modifiedTime=i??Date.now(),s&&(m.lastModifiedBy=s.id),d.createdTime||t||(m.createdTime=m.modifiedTime),d.coreVersion!==o.version&&(m.coreVersion=o.version),t&&!hasSystemDataChanged(e,t)||(d.systemId!==a.system.id&&(m.systemId=a.system.id),d.systemVersion!==a.system.version&&(m.systemVersion=a.system.version)),t?mergeObject(t,{_stats:m}):e.updateSource({_stats:m})}function hasSystemDataChanged(e,t){if(e.schema.has("system")&&("system"in t||"type"in t))return!0;const s=t.flags;if(s){const e=game.system.id;if(e in s||`-=${e}`in s)return!0}return!1}