import * as Types from '@meetalva/types' ; import * as _ from 'lodash' ; import * as uuid from 'uuid' ; import { ElementCandidate } from '@meetalva/types' ; export interface PatternSlotInit { contextId : string ; defaultValue : Types . ElementCandidate | undefined ; displayName : string ; description : string ; example : string ; hidden : boolean ; id : string ; propertyName : string ; required : boolean ; type : Types . SlotType ; quantity : Types . SlotQuantity ; } export class PatternSlot { public readonly model = Types . ModelName . PatternSlot ; private contextId : string ; private displayName : string ; private defaultValue : Types . ElementCandidate | undefined ; private description : string ; private example : string ; private hidden : boolean ; private id : string ; private propertyName : string ; private required : boolean ; private type : Types . SlotType ; private quantity : Types . SlotQuantity ; public constructor ( init ) { this . type = init . type ; this . id = init . id ; this . displayName = init . displayName ; this . defaultValue = init . defaultValue ; this . description = init . description ; this . example = init . example ; this . hidden = init . hidden ; this . required = init . required ; this . type = init . type ; this . propertyName = init . propertyName ; this . contextId = init . contextId ; this . quantity = init . quantity ; } public static from ( serialized ) { return new PatternSlot ( { contextId : serialized . contextId , description : serialized . description , defaultValue : serialized . defaultValue , displayName : serialized . label , example : serialized . example , hidden : serialized . hidden , id : serialized . id , propertyName : serialized . propertyName , required : serialized . required , quantity : toSlotQuantity ( serialized . quantity ) , type : toSlotType ( serialized . type ) } ) ; } public clone ( ) { return new PatternSlot ( { contextId : this . contextId , description : this . description , displayName : this . displayName , defaultValue : this . defaultValue , example : this . example , hidden : this . hidden , id : uuid . v4 ( ) , propertyName : this . propertyName , required : this . required , quantity : toSlotQuantity ( this . quantity ) , type : toSlotType ( this . type ) } ) ; } public equals ( b ) { return _ . isEqual ( this . toJSON ( ) , b . toJSON ( ) ) ; } public getContextId ( ) { return this . contextId ; } public getDefaultValue ( ) { return this . defaultValue ; } public getHidden ( ) { return this . hidden ; } public getId ( ) { return this . id ; } public getName ( ) { return this . displayName ; } public getPropertyName ( ) { return this . propertyName ; } public getRequired ( ) { return this . required ; } public getQuantity ( ) { return this . quantity ; } public getType ( ) { return this . type ; } public toJSON ( ) { return { model : this . model , contextId : this . contextId , description : this . description , defaultValue : this . defaultValue , example : this . example , hidden : this . hidden , label : this . displayName , propertyName : this . propertyName , id : this . id , required : this . required , quantity : this . quantity , type : this . type } ; } public update ( b ) { this . contextId = b . contextId ; this . description = b . description ; this . defaultValue = b . defaultValue ; this . example = b . example ; this . hidden = b . hidden ; this . displayName = b . displayName ; this . propertyName = b . propertyName ; this . required = b . required ; this . quantity = toSlotQuantity ( b . quantity ) ; this . type = toSlotType ( b . type ) ; } } function toSlotType ( type ) { switch ( type ) { case 'property' : return Types . SlotType . Property ; case 'children' : default : return Types . SlotType . Children ; } } function toSlotQuantity ( quantity ) { switch ( quantity ) { case 'single' : return Types . SlotQuantity . Single ; case 'multiple' : default : return Types . SlotQuantity . Multiple ; } }