package Ġcom . art uro g ut ier rez . op enticator . domain . account . inter actor Ċ Ċ import Ġcom . art uro g ut ier rez . op enticator . domain . account . inter actor . Add Account Interactor . Params Ċ import Ġcom . art uro g ut ier rez . op enticator . domain . account . model . Account Ċ import Ġcom . art uro g ut ier rez . op enticator . domain . account . repository . Account Repository Ċ import Ġcom . art uro g ut ier rez . op enticator . domain . category . Category Factory Ċ import Ġcom . art uro g ut ier rez . op enticator . domain . category . Category Selector Ċ import Ġcom . art uro g ut ier rez . op enticator . domain . category . repository . Category Repository Ċ import Ġcom . art uro g ut ier rez . op enticator . executor . Post Execution Thread Ċ import Ġcom . art uro g ut ier rez . op enticator . executor . Thread Executor Ċ import Ġcom . art uro g ut ier rez . op enticator . inter actor . Single UseCase Ċ import Ġio . reactivex . Single Ċ Ċ class ĠAdd Account Interactor ( private Ġval Ġaccount Repository : ĠAccount Repository , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġcategory Repository : ĠCategory Repository , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġcategory Selector : ĠCategory Selector , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġcategory Factory : ĠCategory Factory , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthread Executor : ĠThread Executor , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpost Execution Thread : ĠPost Execution Thread ) Ġ: ĠSingle UseCase < Account , ĠParams >( thread Executor , Ġpost Execution Thread ) Ġ{ ĊĊĠ Ġpublic Ġoverride Ġfun Ġbuild Observable ( params : ĠParams ): ĠSingle < Account > Ġ{ ĊĠĠĠ Ġval Ġnew Account Ġ= Ġparams . account ĊĊĠĠĠ Ġreturn Ġcategory Selector . selected Category ĊĠĠĠĠĠĠĠ Ġ. flatMap Single Ġ{ Ġcategory Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġval Ġempty Category Ġ= Ġcategory Factory . create Empty Category () ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( category Ġ== Ġempty Category ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Repository . add ( new Account ) ĊĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Repository . add ( new Account ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġcreated Account Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcategory Repository . add Account ( category , Ġnew Account ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ ĠSingle . just ( created Account ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}. first Or Error () ĊĠ Ġ} ĊĊĠ Ġdata Ġclass ĠParams ( val Ġaccount : ĠAccount ) Ċ } Ċ