{"version":3,"file":"ActionMenuRecord.mjs","names":[],"sources":["../../src/repository/ActionMenuRecord.ts"],"sourcesContent":["import type { TagsBase } from '@credo-ts/core'\nimport { BaseRecord, CredoError, utils } from '@credo-ts/core'\nimport { Type } from 'class-transformer'\nimport type { ActionMenuRole } from '../ActionMenuRole'\nimport type { ActionMenuState } from '../ActionMenuState'\n\nimport { ActionMenu, ActionMenuSelection } from '../models'\n\n/**\n * @public\n */\nexport interface ActionMenuRecordProps {\n  id?: string\n  state: ActionMenuState\n  role: ActionMenuRole\n  createdAt?: Date\n  connectionId: string\n  threadId: string\n  menu?: ActionMenu\n  performedAction?: ActionMenuSelection\n  tags?: CustomActionMenuTags\n}\n\n/**\n * @public\n */\nexport type CustomActionMenuTags = TagsBase\n\n/**\n * @public\n */\nexport type DefaultActionMenuTags = {\n  role: ActionMenuRole\n  connectionId: string\n  threadId: string\n}\n\n/**\n * @public\n */\nexport class ActionMenuRecord\n  extends BaseRecord<DefaultActionMenuTags, CustomActionMenuTags>\n  implements ActionMenuRecordProps\n{\n  public state!: ActionMenuState\n  public role!: ActionMenuRole\n  public connectionId!: string\n  public threadId!: string\n\n  @Type(() => ActionMenu)\n  public menu?: ActionMenu\n\n  @Type(() => ActionMenuSelection)\n  public performedAction?: ActionMenuSelection\n\n  public static readonly type = 'ActionMenuRecord'\n  public readonly type = ActionMenuRecord.type\n\n  public constructor(props: ActionMenuRecordProps) {\n    super()\n\n    if (props) {\n      this.id = props.id ?? utils.uuid()\n      this.createdAt = props.createdAt ?? new Date()\n      this.connectionId = props.connectionId\n      this.threadId = props.threadId\n      this.state = props.state\n      this.role = props.role\n      this.menu = props.menu\n      this.performedAction = props.performedAction\n      this._tags = props.tags ?? {}\n    }\n  }\n\n  public getTags() {\n    return {\n      ...this._tags,\n      role: this.role,\n      connectionId: this.connectionId,\n      threadId: this.threadId,\n    }\n  }\n\n  public assertState(expectedStates: ActionMenuState | ActionMenuState[]) {\n    if (!Array.isArray(expectedStates)) {\n      expectedStates = [expectedStates]\n    }\n\n    if (!expectedStates.includes(this.state)) {\n      throw new CredoError(\n        `Action Menu record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(', ')}.`\n      )\n    }\n  }\n\n  public assertRole(expectedRole: ActionMenuRole) {\n    if (this.role !== expectedRole) {\n      throw new CredoError(`Action Menu record has invalid role ${this.role}. Expected role ${expectedRole}.`)\n    }\n  }\n}\n"],"mappings":";;;;;;;;;;;;;AAwCA,IAAa,mBAAb,MAAa,yBACH,WAEV;CAeE,AAAO,YAAY,OAA8B;AAC/C,SAAO;OAHO,OAAO,iBAAiB;AAKtC,MAAI,OAAO;AACT,QAAK,KAAK,MAAM,MAAM,MAAM,MAAM;AAClC,QAAK,YAAY,MAAM,6BAAa,IAAI,MAAM;AAC9C,QAAK,eAAe,MAAM;AAC1B,QAAK,WAAW,MAAM;AACtB,QAAK,QAAQ,MAAM;AACnB,QAAK,OAAO,MAAM;AAClB,QAAK,OAAO,MAAM;AAClB,QAAK,kBAAkB,MAAM;AAC7B,QAAK,QAAQ,MAAM,QAAQ,EAAE;;;CAIjC,AAAO,UAAU;AACf,SAAO;GACL,GAAG,KAAK;GACR,MAAM,KAAK;GACX,cAAc,KAAK;GACnB,UAAU,KAAK;GAChB;;CAGH,AAAO,YAAY,gBAAqD;AACtE,MAAI,CAAC,MAAM,QAAQ,eAAe,CAChC,kBAAiB,CAAC,eAAe;AAGnC,MAAI,CAAC,eAAe,SAAS,KAAK,MAAM,CACtC,OAAM,IAAI,WACR,0CAA0C,KAAK,MAAM,sBAAsB,eAAe,KAAK,KAAK,CAAC,GACtG;;CAIL,AAAO,WAAW,cAA8B;AAC9C,MAAI,KAAK,SAAS,aAChB,OAAM,IAAI,WAAW,uCAAuC,KAAK,KAAK,kBAAkB,aAAa,GAAG;;;iBA1CrF,OAAO;YAN7B,WAAW,WAAW;YAGtB,WAAW,oBAAoB"}