import BaseActor from"../../../common/documents/actor.mjs";import ServerDocumentMixin from"../backend/server-document.mjs";import{IMAGE_FILE_EXTENSIONS,VIDEO_FILE_EXTENSIONS}from"../../../common/constants.mjs";import{getType}from"../../../common/utils/helpers.mjs";import Files from"../../files/files.mjs";import Token from"./token.mjs";export default class Actor extends(ServerDocumentMixin(BaseActor)){static _migrationRegistry=[...super._migrationRegistry,{fn:migrateV10Fields,version:12},...Token._migrationRegistry.map((e=>({...e,fn:t=>{const r=t.prototypeToken;return"Object"===getType(r)&&e.fn(r)}})))];static socketListeners(e){e.on("requestTokenImages",this.#e.bind(this,e))}static async#e(e,t,{pack:r=null},o){const s=r?db.packs.get(r):db.Actor;if(!s.ready)return o({error:`The "${r}" database is not yet connected.`});const n=await s.get(t),i=n?.testUserPermission(e.user,"OWNER");if(!e.user.hasPermission("FILES_BROWSE")&&!i)return o({error:`You do not have permission to query wildcard token images for Actor [${t}].`});const a=n.prototypeToken;if(!a.randomImg)return o({files:[a.texture.src]});const{source:c,pattern:m,browseOptions:d}=Files.parseWildcardPath(a.texture.src);d.isAdmin=!0,d.target=m,d.extensions=Object.keys(IMAGE_FILE_EXTENSIONS).concat(Object.keys(VIDEO_FILE_EXTENSIONS)).map((e=>`.${e}`));config.files.storages[c].getFiles(d).then(o).catch((e=>o({error:e.message})))}}function migrateV10Fields(e){const t=Actor._addDataFieldMigration(e,"data","system"),r=Actor._addDataFieldMigration(e,"token","prototypeToken");return t||r}