package Ġorg . j dc . template . model . repository Ċ Ċ import Ġandroidx . room . with Transaction Ċ import Ġorg . j dc . template . model . db . main . Main Database Wrapper Ċ import Ġorg . j dc . template . model . db . main . aff ili ate . Aff ili ate Ċ import Ġorg . j dc . template . model . db . main . individual . Individual Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Singleton Ċ class ĠIndividual Repository Ċ @ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġmain Database Wrapper : ĠMain Database Wrapper Ċ ){ ĊĠĠĠ Ġprivate Ġfun Ġmain Database () Ġ= Ġmain Database Wrapper . get Database () ĊĊĠĠĠ Ġprivate Ġfun Ġindividual Dao () Ġ= Ġmain Database (). individual Dao ĊĠĠĠ Ġprivate Ġfun Ġhouse hold Dao () Ġ= Ġmain Database (). aff ili ate Dao ĊĠĠĠ Ġprivate Ġfun Ġdirectory Item Dao () Ġ= Ġmain Database (). directory Item Dao ĊĊĠĠĠ Ġfun Ġget Directory List Flow () Ġ= Ġdirectory Item Dao (). findAll Direct Items Flow () ĊĠĠĠ Ġsuspend Ġfun Ġget Individual ( individual Id : ĠLong ) Ġ= Ġindividual Dao (). findById ( individual Id ) ĊĠĠĠ Ġfun Ġget Individual Flow ( individual Id : ĠLong ) Ġ= Ġindividual Dao (). findById Flow ( individual Id ) ĊĠĠĠ Ġsuspend Ġfun ĠgetAll Individual s () Ġ= Ġindividual Dao (). findAll () ĊĠĠĠ Ġsuspend Ġfun Ġget Individual Count () Ġ= Ġindividual Dao (). find Count () ĊĠĠĠ Ġsuspend Ġfun Ġget Individual FirstName ( individual Id : ĠLong ) Ġ= Ġindividual Dao (). find FirstName ( individual Id ) ĊĊĠĠĠ Ġsuspend Ġfun Ġsave Individual ( individual : ĠIndividual ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( is Previous ly Inserted ( individual )) Ġreturn ĊĊĠĠĠĠĠĠĠ Ġif Ġ( individual . id Ġ<= Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnew Id Ġ= Ġindividual Dao (). insert ( individual ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġindividual . id Ġ= Ġnew Id ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġindividual Dao (). update ( individual ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġsave Aff ili ate ( aff ili ate : ĠAff ili ate ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( aff ili ate . id Ġ<= Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnew Id Ġ= Ġhouse hold Dao (). insert ( aff ili ate ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaffili ate . id Ġ= Ġnew Id ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhouse hold Dao (). update ( aff ili ate ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġsave New Aff ili ate ( lastName : ĠString , Ġindividuals : ĠList < Individual >) Ġ{ ĊĠĠĠĠĠĠĠ Ġmain Database (). with Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaffili ate Ġ= ĠAff ili ate () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaffili ate . name Ġ= ĠlastName ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsave Aff ili ate ( aff ili ate ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġindividuals . forEach Ġ{ Ġindividual Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġindividual . aff ili ate Id Ġ= Ġaffili ate . id ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsave Individual ( individual ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġdelete Individual ( individual Id : ĠLong ) Ġ= Ġindividual Dao (). delete ById ( individual Id ) ĊĊĠĠĠ Ġsuspend Ġfun Ġdelete All Individual s () Ġ{ ĊĠĠĠĠĠĠĠ Ġmain Database (). with Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġindividual Dao (). delete All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhouse hold Dao (). delete All () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun ĠgetAll Members () Ġ= Ġhouse hold Dao (). findAll Members () ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġis Previous ly Inserted ( individual To Insert : ĠIndividual ) Ġ: ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġindividuals Ġ= ĠgetAll Individual s () ĊĠĠĠĠĠĠĠ Ġindividuals . map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( it . equals ( individual To Insert )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġfalse ĊĠĠĠ Ġ} Ċ }