import { computed, makeObservable } from 'mobx'; import { GPS_COORDINATES } from '../constants' import { Element } from '../element' export enum CheckPointType { SELECT = 'Select', TEXT = 'Text', NUMBER = 'Number', PHOTO = 'Photo', } export class CheckPoint 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, { pointType: computed, shouldCreateFinding: computed, options: computed, }) } static get TYPE() { return 'Checkpoint' } static get ATTRIBUTES() { return { ...Element.ATTRIBUTES, COORDINATES: GPS_COORDINATES, ORDER: 'order', TYPE: 'type', SELECT_OPTIONS: 'checkpoint_select_options', SELECT_OPTION_COMPARATOR: 'checkpoint_select_option_comparator', CREATE_FINDING: 'ovakfinding', WORKFLOW_NOTE: 'workflow_note', WORKFLOW_PHOTO: 'workflow_photo', CONDITIONAL_ATE: 'conditional_checkpoint_ate', CONDITIONAL_VALUE: 'conditional_checkpoint_value', } } getConditionalData = (): { value: string; hash: string } | null => { const value = this.getAttributeTextValue(CheckPoint.ATTRIBUTES.CONDITIONAL_VALUE) const hash = this.getAttributeTextValue(CheckPoint.ATTRIBUTES.CONDITIONAL_ATE) if (!value || !hash) { return null } return { value, hash, } } get pointType(): CheckPointType { return this.getAttributeRawValue( CheckPoint.ATTRIBUTES.TYPE, ) as CheckPointType } get shouldCreateFinding() { return this.getAttributeRawValue( (this.constructor as typeof CheckPoint).ATTRIBUTES.CREATE_FINDING, ) === 'Yes' ? true : false } get options(): string[] | undefined { const value = this.getAttributeRawValue( CheckPoint.ATTRIBUTES.SELECT_OPTIONS, ) as string | string[] if (Array.isArray(value)) { return value } return value?.split(',') } }