import { get , set } from '@ember/object' ; import { decoratorWithParams } from '@ember-decorators/utils/decorator' ; import { ensureService , extractArgs , tryDeserialize , trySerialize } from './helpers' ; import type { Args } from './helpers' ; export const queryParam = decoratorWithParams ( queryParamWithOptionalParams ) as unknown as any ; function queryParamWithOptionalParams < T = boolean > ( _target , propertyKey , sourceDescriptor ? , ... args ) { const { get : oldGet , initializer } = sourceDescriptor ; const [ propertyPath , options ] = extractArgs < T > ( args . flat ( ) as Args < T > , propertyKey ) ; const result = { configurable : true , enumerable : true , get : function ( ) : T | undefined { const service = ensureService ( this ) ; const value = get < any , any > ( service , propertyPath ) ; const deserialized = tryDeserialize ( value , options ) ; return deserialized ?? oldGet ?. ( ) ?? initializer ?. ( ) ; } , set : function ( value ? ) { const service = ensureService ( this ) ; const serialized = trySerialize ( value , options ) ; set < any , any > ( service , propertyPath , serialized ) ; } , } ; return result as any ; }