--[[----------------------------------------------------------------------------

LrRxNotificationDbDefinitions.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2018 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

local WFArguments = require 'WFArguments'

--------------------------------------------------------------------------------

local check = assert( WFArguments.check )

--============================================================================--

-- @mark LrRxNotificationDbDefinitions namespace
-- sqlite table definitions in rxDatabase
-- rxDatabase is a sqlite database which allows directly add value and query from

local LrRxNotificationDbDefinitions = {}

--------------------------------------------------------------------------------

function LrRxNotificationDbDefinitions.generateSchema( rxDatabase )

	check( 'WFRxDatabaseImp' )

	-- table notifications

	-- needsUpdateOnANS indicates that the notification is in sync with ANS. 
	-- Needs to be set when read or visited is changed locally

	rxDatabase:addTable(
		[[CREATE TABLE notifications(
			notificationId UNIQUE,
			subtype,
			time,
			read,
			payloadJsonString,
			visited DEFAULT 0,
			needsUpdateOnANS DEFAULT 0
		)]])
		:onConflict( 'alter', {
			[[ALTER TABLE notifications ADD COLUMN visited DEFAULT 0]], -- WF-1318
			[[ALTER TABLE notifications ADD COLUMN needsUpdateOnANS DEFAULT 0]], -- WF-1318
		} )

	rxDatabase:addIndex [[CREATE INDEX notifications_id ON notifications( notificationId )]]
	rxDatabase:addIndex [[CREATE INDEX notifications_time ON notifications( time )]]
	rxDatabase:addIndex [[CREATE INDEX notifications_subtype ON notifications( subtype )]]

	-- table notificationInfo
	
	rxDatabase:addTable(
		[[CREATE TABLE notificationInfo( key UNIQUE, value )]])

end

--------------------------------------------------------------------------------

return LrRxNotificationDbDefinitions
