import { computed, makeObservable } from 'mobx'; import { IListingConfig, IListingPreset, } from '../../interfaces/listing.interface' import { Listing } from '../../services' import { Element } from '../element' export const LISTING_CONFIG_VERSION = { V1: 'v1', V2: 'v2', } export class ListingConfig extends Element { // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(...args: any) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore: this is fine super(...args); makeObservable(this, { config: computed, }) } static get TYPE() { return 'ListingConfig' } get config(): IListingConfig | null { const textConfig = this.getAttributeRawValue( (this.constructor as typeof ListingConfig).ATTRIBUTES.CONFIG, ) as string const configVersion = this.getAttributeRawValue( (this.constructor as typeof ListingConfig).ATTRIBUTES.CONFIG_VERSION, ) as string try { const config: IListingPreset | IListingConfig = JSON.parse(textConfig) if (configVersion === LISTING_CONFIG_VERSION.V2) { return config as IListingConfig } return Listing.parsePresetConfig(config) } catch (e) { console.error('ListingPreset parsing failed.', e) return null } } static get ATTRIBUTES() { return { ...Element.ATTRIBUTES, CONFIG: 'config', TYPE_OF_USAGE: 'type_of_usage', DEFAULT_ACTIVE: 'default_active_map_listing', CONFIG_VERSION: 'version', } } static get SHORTNAME() { return 'Listing' } }