/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 2 , ĠPat rick ĠWil mes Ġ< pat rick . wil mes @ bit - lake . com > Ċ Ġ* Ċ Ġ* ĠSPDX - License - Identifier : ĠBSD - 2 - Clause Ċ Ġ*/ Ċ package Ġsettings Ċ Ċ import Ġorg . jetbrains . ex posed . sql .* Ċ import Ġorg . jetbrains . ex posed . sql . transactions . transaction Ċ import Ġsettings . Settings Table . hours Per Week Ċ import Ġsettings . Settings Table . remote Server Address Ċ import Ġsettings . Settings Table . store Data Remote Ċ import Ġsettings . Settings Table . track Time On Week end Ċ Ċ object ĠSettings Table Ġ: ĠTable ( name Ġ= Ġ" settings ") Ġ{ ĊĠĠĠ Ġval Ġid Ġ= Ġinteger (" id "). auto Increment () ĊĠĠĠ Ġval Ġtrack Time On Week end Ġ= Ġbool ( name Ġ= Ġ" track _ time _ on _ week end ") ĊĠĠĠ Ġval Ġhours Per Week Ġ= Ġinteger ( name Ġ= Ġ" hours _ per _ week ") ĊĠĠĠ Ġval Ġstore Data Remote Ġ= Ġbool ( name Ġ= Ġ" store _ data _ remote ") ĊĠĠĠ Ġval Ġremote Server Address Ġ= Ġtext ( name Ġ= Ġ" remote _ server _ address ") ĊĊĠĠĠ Ġoverride Ġval Ġprimary Key Ġ= ĠPrimary Key ( id ) Ċ } Ċ Ċ fun Ġsave Settings ( settings : ĠSettings ) Ġ{ ĊĠĠĠ Ġtransaction Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( Settings Table . selectAll (). count () Ġ== Ġ 0 L ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSettings Table . insert Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ track Time On Week end ] Ġ= Ġsettings . track Time On Week end ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ hours Per Week ] Ġ= Ġsettings . hours Per Week ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ store Data Remote ] Ġ= Ġsettings . store Data Remote ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ remote Server Address ] Ġ= Ġsettings . remote Server Address ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġid Ġ= ĠSettings Table . selectAll (). first ()[ Settings Table . id ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSettings Table . update ({ ĠSettings Table . id Ġeq Ġid Ġ}) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ track Time On Week end ] Ġ= Ġsettings . track Time On Week end ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ hours Per Week ] Ġ= Ġsettings . hours Per Week ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ store Data Remote ] Ġ= Ġsettings . store Data Remote ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit [ remote Server Address ] Ġ= Ġsettings . remote Server Address ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun Ġget Settings () Ġ= Ġtransaction Ġ{ ĊĠĠĠ ĠSettings Table ĊĠĠĠĠĠĠĠ Ġ. selectAll () ĊĠĠĠĠĠĠĠ Ġ. first OrNull () ĊĠĠĠĠĠĠĠ Ġ? . to Settings () Ġ?: ĠSettings () Ċ } Ċ Ċ private Ġfun ĠResult Row . to Settings () Ġ= ĠSettings ( ĊĠĠĠ Ġtrack Time On Week end Ġ= Ġthis [ track Time On Week end ], ĊĠĠĠ Ġhours Per Week Ġ= Ġif Ġ( this [ hours Per Week ] Ġ== Ġ 0 ) Ġ 4 0 Ġelse Ġthis [ hours Per Week ], ĊĠĠĠ Ġstore Data Remote Ġ= Ġthis [ store Data Remote ], ĊĠĠĠ Ġremote Server Address Ġ= Ġthis [ remote Server Address ], Ċ ) Ċ