-- available bookings - task 2
-- changes:
--   changed BookingDate (Reserved) data type from date to datetime, because I assumed that Little Lemon
--   allows wants bookings per day and table - a table is considered blocked for 2 hours
-- noqa: disable=CP03,LT02,RF03
create function TableIsFree(Reserved datetime, TableNumber int)
returns boolean
deterministic
begin
    return (select not exists (
        select BookingID
        from Bookings as B
        where
            abs(timestampdiff(second, B.Reserved, Reserved)) < 2 * 60 * 60
            and B.TableNumber = TableNumber
    ));
end
