/* Ċ Ġ* ĠCopyright Ġ 2 0 1 8 ĠGoogle ĠLLC Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġapp . t ivi . data . repositories . episodes Ċ Ċ import Ġapp . t ivi . data . entities . Episode Ċ import Ġapp . t ivi . data . entities . Episode Watch Entry Ċ import Ġapp . t ivi . data . entities . Error Result Ċ import Ġapp . t ivi . data . entities . Result Ċ import Ġapp . t ivi . data . entities . Season Ċ import Ġapp . t ivi . data . map pers . Episode Id To Tr akt Id Mapper Ċ import Ġapp . t ivi . data . map pers . Season Id To Tr akt Id Mapper Ċ import Ġapp . t ivi . data . map pers . Show Id To Tr akt Id Mapper Ċ import Ġapp . t ivi . data . map pers . Tr akt History Entry To Episode Ċ import Ġapp . t ivi . data . map pers . Tr akt History Item To Episode Watch Entry Ċ import Ġapp . t ivi . data . map pers . Tr akt Season To Season With Episode s Ċ import Ġapp . t ivi . data . map pers . pair Mapper Of Ċ import Ġapp . t ivi . data . map pers . toList Mapper Ċ import Ġapp . t ivi . extensions . execute With Retry Ċ import Ġapp . t ivi . extensions . to Result Ċ import Ġapp . t ivi . extensions . to Result Unit Ċ import Ġcom . uw et rott mann . tr akt 5 . entities . Episode Ids Ċ import Ġcom . uw et rott mann . tr akt 5 . entities . Sync Episode Ċ import Ġcom . uw et rott mann . tr akt 5 . entities . Sync Items Ċ import Ġcom . uw et rott mann . tr akt 5 . entities . User Slug Ċ import Ġcom . uw et rott mann . tr akt 5 . enums . Extended Ċ import Ġcom . uw et rott mann . tr akt 5 . enums . History Type Ċ import Ġcom . uw et rott mann . tr akt 5 . services . Se asons Ċ import Ġcom . uw et rott mann . tr akt 5 . services . Sync Ċ import Ġcom . uw et rott mann . tr akt 5 . services . Users Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Provider Ċ import Ġorg . th reet en . bp . Offset DateTime Ċ import Ġorg . th reet en . bp . Zone Offset Ċ Ċ class ĠTr akt Se asons Episode s DataSource Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġshow Id To Tr akt Id Mapper : ĠShow Id To Tr akt Id Mapper , ĊĠĠĠ Ġprivate Ġval Ġseason Id To Tr akt Id Mapper : ĠSe ason Id To Tr akt Id Mapper , ĊĠĠĠ Ġprivate Ġval Ġepisode Id To Tr akt Id Mapper : ĠEp isode Id To Tr akt Id Mapper , ĊĠĠĠ Ġprivate Ġval Ġse asons Service : ĠProvider < Se asons >, ĊĠĠĠ Ġprivate Ġval Ġusers Service : ĠProvider < Users >, ĊĠĠĠ Ġprivate Ġval Ġsync Service : ĠProvider < Sync >, ĊĠĠĠ Ġprivate Ġval Ġseason Mapper : ĠTr akt Season To Season With Episode s , ĊĠĠĠ Ġprivate Ġval Ġepisode Mapper : ĠTr akt History Entry To Episode , ĊĠĠĠ Ġprivate Ġval Ġhistory Item Mapper : ĠTr akt History Item To Episode Watch Entry Ċ ) Ġ: ĠSe asons Episode s DataSource Ġ{ ĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget Se asons Episode s ( show Id : ĠLong ): ĠResult < List < Pair < Season , ĠList < Episode >>>> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġse asons Service . get (). summary ( show Id To Tr akt Id Mapper . map ( show Id ). toString (), ĠExtended . FUL LE PI SO DES ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. execute With Retry () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Result ( season Mapper . toList Mapper ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget Show Episode W atches ( ĊĠĠĠĠĠĠĠ Ġshow Id : ĠLong , ĊĠĠĠĠĠĠĠ Ġsince : ĠOffset DateTime ? ĊĠĠĠ Ġ): ĠResult < List < Pair < Episode , ĠEp isode Watch Entry >>> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġshow Tr akt Id Ġ= Ġshow Id To Tr akt Id Mapper . map ( show Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġreturn ĠError Result ( message Ġ= Ġ" No ĠTr akt ĠID Ġfor Ġshow Ġwith ĠID : Ġ$ show Id ") ĊĊĠĠĠĠĠĠĠ Ġreturn Ġusers Service . get (). history ( User Slug . ME , ĠHistory Type . SHO WS , Ġshow Tr akt Id , ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 , Ġ 1 0 0 0 0 , ĠExtended . NO SE ASON S , Ġsince , Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. execute With Retry () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Result ( pair Mapper Of ( episode Mapper , Ġhistory Item Mapper )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget Season W atches ( ĊĠĠĠĠĠĠĠ Ġseason Id : ĠLong , ĊĠĠĠĠĠĠĠ Ġsince : ĠOffset DateTime ? ĊĠĠĠ Ġ): ĠResult < List < Pair < Episode , ĠEp isode Watch Entry >>> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġusers Service . get (). history ( User Slug . ME , ĠHistory Type . SE ASON S , Ġseason Id To Tr akt Id Mapper . map ( season Id ), ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 , Ġ 1 0 0 0 0 , ĠExtended . NO SE ASON S , Ġsince , Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. execute With Retry () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Result ( pair Mapper Of ( episode Mapper , Ġhistory Item Mapper )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget Episode W atches ( ĊĠĠĠĠĠĠĠ Ġepisode Id : ĠLong , ĊĠĠĠĠĠĠĠ Ġsince : ĠOffset DateTime ? ĊĠĠĠ Ġ): ĠResult < List < Episode Watch Entry >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġusers Service . get (). history ( User Slug . ME , ĠHistory Type . E PI SO DES , Ġepisode Id To Tr akt Id Mapper . map ( episode Id ), ĊĠĠĠĠĠĠĠĠĠĠĠĠ 0 , Ġ 1 0 0 0 0 , ĠExtended . NO SE ASON S , Ġsince , Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. execute With Retry () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Result ( history Item Mapper . toList Mapper ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġadd Episode W atches ( w atches : ĠList < Episode Watch Entry >): ĠResult < Unit > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġitems Ġ= ĠSync Items () ĊĠĠĠĠĠĠĠ Ġitems . episodes Ġ= Ġw atches . map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSync Episode () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. id ( Episode Ids . tr akt ( episode Id To Tr akt Id Mapper . map ( it . episode Id ))) !! ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. w atched At ( it . w atched At . with Offset Same Instant ( Zone Offset . UTC )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġsync Service . get (). add Items To W atched History ( items ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. execute With Retry () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Result Unit () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġremove Episode W atches ( w atches : ĠList < Episode Watch Entry >): ĠResult < Unit > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġitems Ġ= ĠSync Items () ĊĠĠĠĠĠĠĠ Ġitems . ids Ġ= Ġw atches . map NotNull Ġ{ Ġit . tr akt Id Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġsync Service . get (). delete Items From W atched History ( items ). execute With Retry () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Result Unit () ĊĠĠĠ Ġ} Ċ } Ċ