CREATE TABLE study_space_hours (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    study_space_id UUID REFERENCES study_spaces(id) ON DELETE CASCADE,
    day_of_week INT CHECK (day_of_week BETWEEN 0 AND 6),  -- 0 = Sunday, 6 = Saturday
    opens_at TIME NOT NULL,
    closes_at TIME NOT NULL,
    is_24_7 BOOLEAN DEFAULT FALSE,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now()
);

CREATE TRIGGER study_space_hours_updated_at
AFTER UPDATE ON study_space_hours
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();