-- Массивы имен и фамилий для генерации
DO $$
DECLARE
    first_names TEXT[] := ARRAY['Aleksandr', 'Dmitriy', 'Maksim', 'Ivan', 'Artem', 'Mikhail', 'Daniil', 'Egor', 'Andrey', 'Nikita', 
                                  'Anna', 'Mariya', 'Elena', 'Olga', 'Ekaterina', 'Natalya', 'Tatyana', 'Irina', 'Yuliya', 'Svetlana'];
    last_names TEXT[] := ARRAY['Ivanov', 'Petrov', 'Sidorov', 'Smirnov', 'Kuznetsov', 'Popov', 'Vasilev', 'Sokolov', 'Mikhaylov', 'Novikov',
                                'Fedorov', 'Morozov', 'Volkov', 'Alekseev', 'Lebedev', 'Semenov', 'Egorov', 'Pavlov', 'Kozlov', 'Stepanov'];
    room_record RECORD;
    residents_count INT;
    i INT;
    first_name TEXT;
    last_name TEXT;
BEGIN
    FOR room_record IN SELECT id FROM rooms LOOP
        residents_count := 2 + floor(random() * 2)::INT;
        
        FOR i IN 1..residents_count LOOP
            first_name := first_names[1 + floor(random() * array_length(first_names, 1))::INT];
            last_name := last_names[1 + floor(random() * array_length(last_names, 1))::INT];
            
            INSERT INTO residents (real_name, room, is_busy, active_hours, inactive_hours, created_at, updated_at)
            VALUES (first_name || ' ' || last_name, room_record.id, false, 0, 0, NOW(), NOW());
        END LOOP;
    END LOOP;
END $$;
