// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("require ../chunks/tslib.es6 ../core/Error ../core/JSONSupport ../core/accessorSupport/decorators/property ../core/has ../core/Logger ../core/RandomLCG ../core/accessorSupport/decorators/subclass ./PortalFolder ./PortalGroup".split(" "),function(p,d,l,c,e,u,v,w,q,r,n){var m;c=m=class extends c.JSONSupport{constructor(a){super(a);this.userType=this.userLicenseTypeId=this.username=this.units=this.sourceJSON=this.roleId=this.role=this.region=this.privileges=this.preferredView=this.portal=this.orgId= this.modified=this.fullName=this.email=this.description=this.culture=this.created=this.access=null}get thumbnailUrl(){const a=this.url,b=this.thumbnail;return a&&b?this.portal.normalizeUrl(`${a}/info/${b}?f=json`):null}get userContentUrl(){const a=this.portal?.restUrl;return a?`${a}/content/users/${this.username}`:null}get url(){const a=this.portal?.restUrl;return a?`${a}/community/users/${this.username}`:null}addItem(a){const b=a&&a.item;var f=a?.data;a=a?.folder;const g={method:"post"};b&&(g.query= b.createPostQuery(),null!=f&&("string"===typeof f?g.query.text=f:"object"===typeof f&&(g.query.text=JSON.stringify(f))));f=this.userContentUrl;a&&(f+="/"+("string"===typeof a?a:a.id));return this.portal.request(f+"/addItem",g).then(h=>{b.id=h.id;b.portal=this.portal;return b.loaded?b.reload():b.load()})}async deleteItem(a,b=!1){let f=this.userContentUrl;a.ownerFolder&&(f+="/"+a.ownerFolder);await this.portal.request(f+`/items/${a.id}/delete`,{method:"post",query:b?{permanentDelete:!0}:{}});a.id=null; a.portal=null}async deleteItems(a,b=!1){a=a.concat();var f=this.userContentUrl+"/deleteItems";const g=[];var h=a.map(k=>k.id);if(h.length){b={method:"post",query:{items:h.join(","),permanentDelete:b}};f=await this.portal.request(f,b);for(const k of f.results)f=a.find(t=>k.itemId===t.id),b=k.success,h=null,b?(f.id=null,f.portal=null):k.error&&(h=new l("portal:delete-item-failed",k.error.message,k.error)),g.push({item:f,success:b,error:h})}return g}fetchFolders(){return this.portal.request(this.userContentUrl?? "",{query:{num:1}}).then(a=>a&&a.folders?a.folders.map(b=>{b=r.fromJSON(b);b.portal=this.portal;return b}):[])}fetchGroups(){return this.portal.request(this.url??"").then(a=>a&&a.groups?a.groups.map(b=>{b=n.fromJSON(b);b.portal=this.portal;return b}):[])}async fetchItems(a){a??={};var b=this.userContentUrl??"";a.folder&&(b+="/"+a.folder.id);const {default:f}=await new Promise((g,h)=>p(["./PortalItem"],k=>g(Object.freeze(Object.defineProperty({__proto__:null,default:k},Symbol.toStringTag,{value:"Module"}))), h));a=await this.portal.request(b,{query:{folders:!1,inRecycleBin:a.inRecycleBin?!0:null,foldersContent:!a.folder&&a.includeSubfolderItems?!0:null,num:a.num||10,start:a.start||1,sortField:a.sortField||"created",sortOrder:a.sortOrder||"asc"}});return a?.items?(b=a.items.map(g=>{g=f.fromJSON(g);g.portal=this.portal;return g}),await Promise.all(b.map(g=>g.load())),{items:b,nextStart:a.nextStart,total:a.total}):{items:[],nextStart:-1,total:0}}fetchTags(){return this.portal.request(this.url+"/tags").then(a=> a.tags)}getThumbnailUrl(a){let b=this.thumbnailUrl;b&&a&&(b+=`&w=${a}`);return b}queryFavorites(a){return this.favGroupId?(this._favGroup||(this._favGroup=new n({id:this.favGroupId,portal:this.portal})),this._favGroup.queryItems(a)):Promise.reject(new l("internal:unknown","Unknown internal error",{internalError:"Unknown favGroupId"}))}async restoreItem(a,b){await this.portal.request(this.userContentUrl+`/items/${a.id}/restore`,{method:"post",query:b?{folderID:"string"===typeof b?b:b.id}:null})}toJSON(){throw new l("internal:not-yet-implemented", "PortalUser.toJSON is not yet implemented");}static fromJSON(a){if(!a)return null;if(a.declaredClass)throw Error("JSON object is already hydrated");const b=new m({sourceJSON:a});b.read(a);return b}};d.__decorate([e.property()],c.prototype,"access",void 0);d.__decorate([e.property({type:Date})],c.prototype,"created",void 0);d.__decorate([e.property()],c.prototype,"culture",void 0);d.__decorate([e.property()],c.prototype,"description",void 0);d.__decorate([e.property()],c.prototype,"email",void 0); d.__decorate([e.property()],c.prototype,"favGroupId",void 0);d.__decorate([e.property()],c.prototype,"fullName",void 0);d.__decorate([e.property({type:Date})],c.prototype,"modified",void 0);d.__decorate([e.property()],c.prototype,"orgId",void 0);d.__decorate([e.property()],c.prototype,"portal",void 0);d.__decorate([e.property()],c.prototype,"preferredView",void 0);d.__decorate([e.property()],c.prototype,"privileges",void 0);d.__decorate([e.property()],c.prototype,"region",void 0);d.__decorate([e.property()], c.prototype,"role",void 0);d.__decorate([e.property()],c.prototype,"roleId",void 0);d.__decorate([e.property()],c.prototype,"sourceJSON",void 0);d.__decorate([e.property()],c.prototype,"thumbnail",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"thumbnailUrl",null);d.__decorate([e.property()],c.prototype,"units",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"userContentUrl",null);d.__decorate([e.property({readOnly:!0})],c.prototype,"url",null);d.__decorate([e.property()], c.prototype,"username",void 0);d.__decorate([e.property()],c.prototype,"userLicenseTypeId",void 0);d.__decorate([e.property()],c.prototype,"userType",void 0);return c=m=d.__decorate([q.subclass("esri.portal.PortalUser")],c)});