import ConditionTypes, { ExpressionTypes, OperatorTypes } from '../constants/ConditionTypes'; import EntityPropertyTypes from '../constants/EntityPropertyTypes'; import FormStepTypes from '../constants/FormStepTypes'; import { Time } from './Time'; export type Condition = ExpressionCondition | FormStepCondition | EntityValueCondition; export interface ExpressionCondition { type: ConditionTypes.EXPRESSION; conditions: (Type | ExpressionCondition)[]; expression: ExpressionTypes; } export type FormStepCondition = ExistanceFormStepCondition | CheckBoxFormStepCondition | TimePickerFormStepCondition | ClassifierSelectorFormStepCondition | DatePickerFormStepCondition | EntityValuePickerFormStepCondition | RatingFormStepCondition | SelectorFormStepCondition | TextAreaFormStepCondition | TextInputFormStepCondition; interface BaseFormStepCondition { type: ConditionTypes.FORM_STEP; operator: OperatorTypes; stepType: FormStepTypes; idStep: string; } export interface ExistanceFormStepCondition extends BaseFormStepCondition { operator: OperatorTypes.EXISTS | OperatorTypes.NOTEXISTS; } export interface CheckBoxFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.CHECKBOX; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; value: boolean; } export interface ClassifierSelectorFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.CLASSIFIER_SELECTOR; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; idRoot: string; idValue: string; } export interface DatePickerFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.DATEPICKER; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.LESS | OperatorTypes.MORE; value: Date; } export interface EntityValuePickerFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.ENTITYVALUEPICKER; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; values: string[]; } export interface RatingFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.RATING; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.LESS | OperatorTypes.MORE; value: number; } export interface SelectorFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.SELECTOR; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; value: string; } export interface TextAreaFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.TEXTAREA; operator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; values: string[]; } export interface TextInputFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.TEXTINPUT; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; value: string; } export type TimePickerFormStepCondition = BaseTimePickerFormStepCondition | WorkingTimePickerFormStepCondition; export interface BaseTimePickerFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.TIMEPICKER; operator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; property: Omit; propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.MORE | OperatorTypes.LESS; value: number; } export interface WorkingTimePickerFormStepCondition extends BaseFormStepCondition { stepType: FormStepTypes.TIMEPICKER; operator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; property: 'working'; propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; value: boolean; } export type EntityValueCondition = EntityEqualsCondition | EntityPropertyCondition; export type EntityPropertyCondition = EntityPropertyExistsCondition | EntitySelectorCondition | EntityTextInputCondition | EntityTextAreaCondition | EntityCheckboxCondition | EntityDateCondition | EntityTimeCondition | EntityRelativeDateCondition; export interface EntityEqualsCondition { type: ConditionTypes.ENTITYVALUE; idEntity: string; operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; values: string[]; } export interface EntityPropertyConditionBase { type: ConditionTypes.ENTITYVALUE; idEntity: string; operator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; idProperty: string; } export interface EntityPropertyExistsCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes; propertyOperator: OperatorTypes.EXISTS | OperatorTypes.NOTEXISTS; } export interface EntitySelectorCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.SELECTOR; propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; propertyValue: string; } export interface EntityTextInputCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.TEXTINPUT | EntityPropertyTypes.NAME; propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; propertyValue: string; } export interface EntityTextAreaCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.TEXTAREA; propertyOperator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; propertyValues: string[]; } export interface EntityCheckboxCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.CHECKBOX; propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; propertyValue: boolean; } export interface EntityDateCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.DATEPICKER; propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.LESS | OperatorTypes.MORE; propertyValue: Date; } export interface EntityRelativeDateCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.DATEPICKER; propertyOperator: OperatorTypes.PAST_RELATIVE_LESS | OperatorTypes.PAST_RELATIVE_MORE | OperatorTypes.FUTURE_RELATIVE_LESS | OperatorTypes.FUTURE_RELATIVE_MORE; value: { days: number; hours: number; minutes: number; working: boolean; }; } export type EntityTimeCondition = BaseEntityTimeCondition | WorkingEntityTimeCondition; export interface BaseEntityTimeCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.TIMEPICKER; property: Omit; propertyOperator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; timePropertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.MORE | OperatorTypes.LESS; value: number; } export interface WorkingEntityTimeCondition extends EntityPropertyConditionBase { propertyType: EntityPropertyTypes.TIMEPICKER; property: 'working'; propertyOperator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES; timePropertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL; value: boolean; } export {};