/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../core/Accessor","../core/Error","../core/Logger","../core/maybe","../core/urlUtils","../core/accessorSupport/decorators/property","../core/arrayUtils","../core/has","../core/accessorSupport/decorators/cast","../core/accessorSupport/decorators/subclass"],(function(t,e,r,o,a,s,i,l,n,p,c,u,h){"use strict";const m=s.getLogger("esri.portal.PortalItemResource");let y=function(r){function o(t){var e;return(e=r.call(this,t)||this).portalItem=null,e}e._inheritsLoose(o,r);var s=o.prototype;return s.normalizeCtorArgs=function(t){return t&&t.portalItem&&t.path?{...t,path:this._normalizePath(t.path,t.portalItem)}:t},s._castPath=function(t){return this._normalizePath(t,this.portalItem)},s.fetch=function(t="json",e){const r=this.url;if(i.isNone(r))throw new a("portal-item-resource:fetch","Portal item resource does not refer to a valid item or path");return this.portalItem.portal._request(r,{responseType:t,query:{token:this.portalItem.apiKey},signal:i.get(e,"signal")})},s.update=function(){var r=e._asyncToGenerator((function*(e,r){return(yield new Promise(((e,r)=>t(["./support/resourceUtils"],e,r)))).addOrUpdateResource(this,"update",e,r)}));function o(t,e){return r.apply(this,arguments)}return o}(),s.hasPath=function(){return i.isSome(this.path)},s._normalizePath=function(t,e){return i.isNone(t)?t:(t=t.replace(/^\/+/,""),i.isSome(e)&&l.isAbsolute(t)&&(t=l.makeRelative(t,e.itemUrl)),t.replace(/^\/+/,"").replace(/^(\.\/)?resources\//,""))},e._createClass(o,[{key:"path",set:function(t){i.isSome(t)&&l.isAbsolute(t)?m.error("portalitemresource:invalid-path","A portal item resource path must be relative"):this._set("path",t)}},{key:"url",get:function(){return this.portalItem&&this.path?`${this.portalItem.itemUrl}/resources/${this.path}`:null}},{key:"itemRelativeUrl",get:function(){return this.portalItem&&this.path?`./resources/${this.path}`:null}}]),o}(o);r.__decorate([n.property()],y.prototype,"portalItem",void 0),r.__decorate([n.property({type:String,value:null})],y.prototype,"path",null),r.__decorate([u.cast("path")],y.prototype,"_castPath",null),r.__decorate([n.property({type:String,readOnly:!0})],y.prototype,"url",null),r.__decorate([n.property({type:String,readOnly:!0})],y.prototype,"itemRelativeUrl",null),y=r.__decorate([h.subclass("esri.portal.PortalItemResource")],y);return y}));
