import { PromptType , GoalType , ClientGoalState , ClientPromptState } from 'common/models/prompts' ; import { ClientTipsData , InterventionTip } from 'common/models' ; import UserRoles from 'common/models/UserRoles' ; import { BaseUpdateDto } from './updateDto' ; export type BaseClientUpdateDto < T , TState > = BaseUpdateDto < T > & { clientId : string ; states ? : Record < string , Partial < TState > > ; } ; export type BaseRequest < T , TState > = BaseUpdateDto < T > & { client ? : BaseClientUpdateDto < T , TState > ; callerRole ? : UserRoles . Coach | UserRoles . Client ; coachId ? : string ; } ; export type BaseResponse < T , TState > = { affected ? : T [ ] ; clientAffected ? : { types ? : T [ ] ; states ? : Record < string , TState > ; } ; } ; export type Typed < T , Type > = T & { type : Type ; } ; export type EnsureLibraryRequest = void ; export type EnsureLibraryRequestTyped = Typed < EnsureLibraryRequest , 'library' > ; export type PromptsRequest = BaseRequest < PromptType , ClientPromptState > ; export type ClientPromptsRequest = PromptsRequest [ 'client' ] ; export type PromptsRequestTyped = Typed < PromptsRequest , 'prompts' > ; export type PromptsResponse = BaseResponse < PromptType , ClientPromptState > ; export type TipsRequest = BaseRequest < InterventionTip , ClientTipsData > ; export type ClientTipsRequest = TipsRequest [ 'client' ] ; export type TipsRequestTyped = Typed < TipsRequest , 'tips' > ; export type TipsResponse = BaseResponse < InterventionTip , ClientTipsData > ; export type GoalsRequest = BaseRequest < GoalType , ClientGoalState > ; export type GoalsRequestTyped = Typed < GoalsRequest , 'goals' > ; export type GoalsResponse = BaseResponse < GoalType , ClientGoalState > ; export type RequestDto = PromptsRequestTyped | TipsRequestTyped | GoalsRequestTyped | EnsureLibraryRequestTyped ; export type ResponseDto = Typed < PromptsResponse , 'prompts' > | Typed < TipsResponse , 'tips' > | Typed < GoalsResponse , 'goals' > | Typed < { ok : boolean ; } , 'library' > ; export namespace RequestDto { export function isPrompts ( r ) { const jed = r as PromptsRequestTyped ; return ! ! jed ?. type && jed . type === 'prompts' ; } export function isTips ( r ) { const jed = r as TipsRequestTyped ; return ! ! jed ?. type && jed . type === 'tips' ; } export function isGoals ( r ) { const jed = r as GoalsRequestTyped ; return ! ! jed ?. type && jed . type === 'goals' ; } export function isEnsureLibrary ( r ) { const led = r as EnsureLibraryRequestTyped ; return ! ! led ?. type && led . type === 'library' ; } }