-- The shift board grows a calendar. A restaurant first defines its recurring
-- shifts once ("Jutarnja 08:00-16:00", "Vecernja 16:00-00:00") and then drops
-- them onto concrete dates, so templates live in their own table.
CREATE TABLE `shift_templates` (
	`id` text PRIMARY KEY NOT NULL,
	`restaurant_id` text NOT NULL,
	`name` text NOT NULL,
	`starts_at` text NOT NULL,
	`ends_at` text NOT NULL,
	`sort_order` integer DEFAULT 0 NOT NULL,
	`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
	FOREIGN KEY (`restaurant_id`) REFERENCES `restaurants`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `shift_templates_restaurant_name_unique` ON `shift_templates` (`restaurant_id`,`name`);
--> statement-breakpoint

-- A waiter does not always work the whole shift: sometimes 6 hours of a 10-hour
-- span. NULL means "the shift's own hours", anything else overrides them for
-- that one person on that one shift.
ALTER TABLE `shift_waiters` ADD `starts_at` text;
--> statement-breakpoint
ALTER TABLE `shift_waiters` ADD `ends_at` text;
--> statement-breakpoint

-- Whether the guest confirms a waiter call with a second tap ("Obavesti
-- konobara") or the request fires the moment they pick a reason.
ALTER TABLE `restaurant_settings` ADD `call_confirm_enabled` integer DEFAULT 1 NOT NULL;
--> statement-breakpoint
PRAGMA optimize;
