package Ġcom . so yle . stories . use case . scene . character . include Character In Scene Ċ Ċ import Ġcom . so yle . stories . domain . character . Character Ċ import Ġcom . so yle . stories . use case . character . Character Repository Ċ import Ġcom . so yle . stories . use case . character . arc . list All Character Arc s . Character Item Ċ import Ġcom . so yle . stories . domain . scene . Scene Ċ import Ġcom . so yle . stories . domain . scene . Updated Ċ import Ġcom . so yle . stories . domain . story event . Story Event Ċ import Ġcom . so yle . stories . use case . scene . Scene Repository Ċ import Ġcom . so yle . stories . use case . scene . common .* Ċ import Ġcom . so yle . stories . use case . character . Character DoesNotExist Ċ import Ġcom . so yle . stories . use case . scene . No Scene Exists With Story EventId Ċ import Ġcom . so yle . stories . use case . scene . character . list Available Characters . Available Characters ToAdd To Scene Ċ import Ġcom . so yle . stories . use case . scene . character . list Available Characters . List Available Characters To Include In Scene Ċ import Ġcom . so yle . stories . use case . story event . Story Event Repository Ċ import Ġcom . so yle . stories . use case . story event . add Character To Story Event . Add Character To Story Event Ċ import Ġcom . so yle . stories . use case . story event . add Character To Story Event . Included Character In Story Event Ċ import Ġjava . util .* Ċ Ċ class ĠInclude Character In Scene UseCase ( ĊĠĠĠ Ġprivate Ġval Ġscene Repository : ĠScene Repository , ĊĠĠĠ Ġprivate Ġval Ġstory Event Repository : ĠStory Event Repository , ĊĠĠĠ Ġprivate Ġval Ġcharacter Repository : ĠCharacter Repository Ċ ) Ġ: ĠInclude Character In Scene , ĠList Available Characters To Include In Scene Ġ{ ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠList ĠAvailable ĠChar acters Ġto ĠInclude Ġin ĠScene ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġinvoke ( scene Id : ĠUUID , Ġoutput : ĠList Available Characters To Include In Scene . Output Port ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġscene Ġ= Ġscene Repository . get Scene Or Error ( scene Id ) ĊĠĠĠĠĠĠĠ Ġval Ġcharacters Ġ= Ġcharacter Repository . list Characters In Project ( scene . projectId ) ĊĠĠĠĠĠĠĠ Ġval Ġavailable Characters Ġ= Ġcharacters . filter Not Ġ{ Ġscene . includes Character ( it . id ) Ġ}. map Ġ{ ĠCharacter Item ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠAvailable Characters ToAdd To Scene ( scene . id . uuid , Ġavailable Characters ) ĊĠĠĠĠĠĠĠ Ġoutput . receive Available Characters ToAdd To Scene ( response ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠInclude ĠCharacter Ġin ĠScene ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġinvoke ( scene Id : ĠUUID , Ġcharacter Id : ĠUUID , Ġoutput Port : ĠInclude Character In Scene . Output Port ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġget Ġentities Ġfrom Ġrepositories ĊĠĠĠĠĠĠĠ Ġval Ġscene Ġ= Ġscene Repository . get Scene Or Error ( scene Id ) ĊĠĠĠĠĠĠĠ Ġval Ġstory Event Ġ= Ġstory Event Repository . get Story Event ById ( scene . story EventId ) !! ĊĠĠĠĠĠĠĠ Ġval Ġcharacter Ġ= Ġcharacter Repository . get Character Or Error ( character Id ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġupdate Ġscene Ġand Ġbacking Ġstory Ġevent ĊĠĠĠĠĠĠĠ Ġval Ġscene Update Ġ= Ġscene . with Character Included ( character ) ĊĠĠĠĠĠĠĠ Ġval Ġupdated Story Event Ġ= Ġstory Event . with Included Character Id ( character . id ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġpersist Ġscene Ġand Ġbacking Ġstory Ġevent , Ġif Ġupdated Ġsuccessfully ĊĠĠĠĠĠĠĠ Ġif Ġ( scene Update Ġis ĠUpdated ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstory Event Repository . update Story Event ( updated Story Event ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġscene Repository . update Scene ( scene Update . scene ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Model Ġ= ĠInclude Character In Scene . Response Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġscene Update . scene . id , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Character Details ( scene Update . scene , Ġcharacter ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠInclude d Character In Story Event ( story Event . id . uuid , Ġcharacter . id . uuid ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġoutput Port . character Included In Scene ( response Model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠInclude ĠCharacter Ġin ĠScene ĠAfter ĠInclude d Ġin ĠStory ĠEvent ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġinvoke ( ĊĠĠĠĠĠĠĠ Ġresponse : ĠAdd Character To Story Event . Response Model , ĊĠĠĠĠĠĠĠ Ġoutput Port : ĠInclude Character In Scene . Output Port ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġscene Ġ= Ġget Scene ( response ) ĊĠĠĠĠĠĠĠ Ġval Ġcharacter Ġ= Ġget Character ( response ) ĊĠĠĠĠĠĠĠ Ġadd Character IfNot Included ( scene , Ġcharacter ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Model Ġ= ĠInclude Character In Scene . Response Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġscene . id , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Character Details ( scene , Ġcharacter ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġoutput Port . character Included In Scene ( response Model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġget Character Details ( scene : ĠScene , Ġcharacter : ĠCharacter ): ĠInclude d Character In Scene Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprevious Mot iv ations Ġ= ĠPrevious Mot iv ations ( scene , Ġscene Repository ) ĊĠĠĠĠĠĠĠ Ġreturn ĠInclude d Character In Scene ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġscene . id , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter . id , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter . name . value , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ"", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprevious Mot iv ations . getLast Set Mot ivation ( character . id ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġadd Character IfNot Included ( scene : ĠScene , Ġcharacter : ĠCharacter ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! scene . includes Character ( character . id )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġscene Repository . update Scene ( scene . with Character Included ( character ). scene ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġget Character ( response : ĠAdd Character To Story Event . Response Model ) Ġ= ĊĠĠĠĠĠĠĠ Ġ( character Repository . get Character ById ( Character . Id ( response . character Id )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠCharacter DoesNotExist ( response . character Id )) ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġget Scene ( response : ĠAdd Character To Story Event . Response Model ) Ġ= ĊĠĠĠĠĠĠĠ Ġ( scene Repository . get Scene For Story Event ( Story Event . Id ( response . story EventId )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠNo Scene Exists With Story EventId ( response . story EventId )) Ċ Ċ }