-- ═══════════════════════════════════════════════════════════════
-- Seed: Residents and Facility Hierarchy
-- Type: Data
-- Version: 2026-05-08
-- Purpose: Create sample facility hierarchy and residents for testing
--
-- This seed:
-- - Creates sample buildings, apartments, rooms, beds with fixed UUIDs
-- - Creates sample residents (no bed_id or move_in_date - single source of truth in resident_stays)
-- - Creates resident_stays for occupancy tracking (no is_active - derived from move_out_at IS NULL)
-- - Creates sample files for resident documents
-- - Creates resident_documents linking residents to files
-- - Creates resident_events for audit/lifecycle tracking
-- - Idempotent: uses ON CONFLICT with explicit columns and fixed UUIDs
-- - No hierarchical_code fields (generate runtime via joins)
-- - No room.max_capacity or bed.capacity (derive from beds count)
--
-- Dependencies: 001-auth-schema.sql, 002-file-schema.sql, 005-resident-and-facility-schema.sql, 100-seed-roles-permissions.sql, 101-seed-default-users.sql
-- ═══════════════════════════════════════════════════════════════

DO $$
DECLARE
    admin_user_id UUID;
    -- Fixed UUIDs for determinism
    building_a_id UUID := '00000001-0001-0001-0001-000000000001';
    building_b_id UUID := '00000001-0001-0001-0001-000000000002';
    building_c_id UUID := '00000001-0001-0001-0001-000000000003';
    apartment_a101_id UUID := '00000001-0001-0001-0001-000000000004';
    apartment_a102_id UUID := '00000001-0001-0001-0001-000000000005';
    apartment_b201_id UUID := '00000001-0001-0001-0001-000000000006';
    apartment_b202_id UUID := '00000001-0001-0001-0001-000000000007';
    apartment_c301_id UUID := '00000001-0001-0001-0001-000000000008';
    room_101_id UUID := '00000001-0001-0001-0001-000000000009';
    room_102_id UUID := '00000001-0001-0001-0001-000000000010';
    room_201_id UUID := '00000001-0001-0001-0001-000000000011';
    room_202_id UUID := '00000001-0001-0001-0001-000000000012';
    room_301_id UUID := '00000001-0001-0001-0001-000000000013';
    bed_101_1_id UUID := '00000001-0001-0001-0001-000000000014';
    bed_102_1_id UUID := '00000001-0001-0001-0001-000000000015';
    bed_201_1_id UUID := '00000001-0001-0001-0001-000000000016';
    bed_202_2_id UUID := '00000001-0001-0001-0001-000000000017';
    bed_301_1_id UUID := '00000001-0001-0001-0001-000000000018';
    resident_1_id UUID := '00000001-0001-0001-0001-000000000019';
    resident_2_id UUID := '00000001-0001-0001-0001-000000000020';
    resident_3_id UUID := '00000001-0001-0001-0001-000000000021';
    resident_4_id UUID := '00000001-0001-0001-0001-000000000022';
    resident_5_id UUID := '00000001-0001-0001-0001-000000000023';
    -- Fixed UUIDs for files
    file_1_id UUID := '00000001-0001-0001-0001-000000000030';
    file_2_id UUID := '00000001-0001-0001-0001-000000000031';
    file_3_id UUID := '00000001-0001-0001-0001-000000000032';
    file_4_id UUID := '00000001-0001-0001-0001-000000000033';
    file_5_id UUID := '00000001-0001-0001-0001-000000000034';
    file_6_id UUID := '00000001-0001-0001-0001-000000000035';
BEGIN
    SELECT id INTO admin_user_id FROM users WHERE email = 'admin@bekind.com' LIMIT 1;
    
    IF admin_user_id IS NULL THEN
        RAISE NOTICE 'Admin user not found, skipping resident seed';
        RETURN;
    END IF;

    -- ─────────────────────────────────────────────────────────────
    -- Section 1: Seed Facility Hierarchy
    -- ─────────────────────────────────────────────────────────────

    -- Buildings
    INSERT INTO buildings (id, name, code, address, status, created_by, updated_by, created_at, updated_at)
    VALUES
        (building_a_id, 'Tòa nhà A', 'A', '123 Đường ABC, Quận 1, TP.HCM', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (building_b_id, 'Tòa nhà B', 'B', '456 Đường DEF, Quận 2, TP.HCM', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (building_c_id, 'Tòa nhà C', 'C', '789 Đường GHI, Quận 3, TP.HCM', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
    ON CONFLICT (id) DO NOTHING;

    -- Apartments
    INSERT INTO apartments (id, building_id, name, code, floor, status, created_by, updated_by, created_at, updated_at)
    VALUES
        (apartment_a101_id, building_a_id, 'Căn hộ A101', 'A101', 1, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (apartment_a102_id, building_a_id, 'Căn hộ A102', 'A102', 1, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (apartment_b201_id, building_b_id, 'Căn hộ B201', 'B201', 2, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (apartment_b202_id, building_b_id, 'Căn hộ B202', 'B202', 2, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (apartment_c301_id, building_c_id, 'Căn hộ C301', 'C301', 3, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
    ON CONFLICT (id) DO NOTHING;

    -- Rooms
    INSERT INTO rooms (id, apartment_id, name, code, floor, status, created_by, updated_by, created_at, updated_at)
    VALUES
        (room_101_id, apartment_a101_id, 'Phòng 101', '101', 1, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (room_102_id, apartment_a102_id, 'Phòng 102', '102', 1, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (room_201_id, apartment_b201_id, 'Phòng 201', '201', 2, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (room_202_id, apartment_b202_id, 'Phòng 202', '202', 2, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (room_301_id, apartment_c301_id, 'Phòng 301', '301', 3, 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
    ON CONFLICT (id) DO NOTHING;

    -- Beds
    INSERT INTO beds (id, room_id, name, code, status, created_by, updated_by, created_at, updated_at)
    VALUES
        (bed_101_1_id, room_101_id, 'Giường 1', '1', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (bed_102_1_id, room_102_id, 'Giường 1', '1', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (bed_201_1_id, room_201_id, 'Giường 1', '1', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (bed_202_2_id, room_202_id, 'Giường 2', '2', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        (bed_301_1_id, room_301_id, 'Giường 1', '1', 'active', admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
    ON CONFLICT (id) DO NOTHING;

    -- ─────────────────────────────────────────────────────────────
    -- Section 2: Insert Sample Residents (no bed_id, no move_in_date - single source of truth in resident_stays)
    -- ─────────────────────────────────────────────────────────────

    INSERT INTO residents (
        id,
        full_name,
        email,
        phone,
        id_card,
        date_of_birth,
        emergency_contact_name,
        emergency_contact_phone,
        emergency_contact_relationship,
        status,
        created_by,
        updated_by,
        created_at,
        updated_at
    ) VALUES
        (
            resident_1_id,
            'Nguyễn Văn An',
            'nguyenvanan@example.com',
            '+84901234567',
            '001234567890',
            '1990-05-15',
            'Nguyễn Thị Bình',
            '+84902345678',
            'Vợ',
            'active',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            resident_2_id,
            'Trần Thị Bình',
            'tranthibinh@example.com',
            '+84903456789',
            '001234567891',
            '1992-08-20',
            'Trần Văn Cường',
            '+84904567890',
            'Chồng',
            'active',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            resident_3_id,
            'Lê Văn Cường',
            'levancuong@example.com',
            '+84904567891',
            '001234567892',
            '1988-12-10',
            'Lê Thị Dung',
            '+84905678901',
            'Em gái',
            'active',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            resident_4_id,
            'Phạm Thị Dung',
            'phamthidung@example.com',
            '+84905678902',
            '001234567893',
            '1995-03-25',
            'Phạm Văn Em',
            '+84906789012',
            'Anh trai',
            'inactive',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            resident_5_id,
            'Hoàng Văn Em',
            'hoangvanem@example.com',
            '+84907890123',
            '001234567894',
            '1985-07-08',
            'Hoàng Thị Phượng',
            '+84908901234',
            'Vợ',
            'inactive',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        )
    ON CONFLICT (id) DO NOTHING;

    -- ─────────────────────────────────────────────────────────────
    -- Section 3: Insert Resident Stays (occupancy tracking - no is_active, derived from move_out_at IS NULL)
    -- ─────────────────────────────────────────────────────────────

    INSERT INTO resident_stays (id, resident_id, bed_id, move_in_at, move_out_at, created_by, updated_by, created_at, updated_at)
    VALUES
        ('00000001-0001-0001-0001-000000000024', resident_1_id, bed_101_1_id, '2024-01-15'::timestamp, NULL, admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('00000001-0001-0001-0001-000000000025', resident_2_id, bed_102_1_id, '2024-02-01'::timestamp, NULL, admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('00000001-0001-0001-0001-000000000026', resident_3_id, bed_201_1_id, '2023-06-15'::timestamp, NULL, admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('00000001-0001-0001-0001-000000000027', resident_4_id, bed_202_2_id, '2023-07-01'::timestamp, NULL, admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('00000001-0001-0001-0001-000000000028', resident_5_id, bed_301_1_id, '2022-01-10'::timestamp, '2023-12-15'::timestamp, admin_user_id, admin_user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
    ON CONFLICT (id) DO NOTHING;

    -- ─────────────────────────────────────────────────────────────
    -- Section 4: Seed Files (for resident_documents)
    -- ─────────────────────────────────────────────────────────────

    INSERT INTO files (
        id,
        original_name,
        display_name,
        provider,
        bucket_name,
        object_key,
        mime_type,
        extension,
        size_bytes,
        status,
        visibility,
        owner_user_id,
        created_by,
        updated_by,
        created_at,
        updated_at
    ) VALUES
        (
            file_1_id,
            'nguyenvanan_cccd_front.jpg',
            'CCCD Nguyễn Văn An - Mặt trước',
            'local',
            'documents',
            'residents/nguyenvanan_cccd_front.jpg',
            'image/jpeg',
            'jpg',
            256000,
            'ready',
            'private',
            admin_user_id,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            file_2_id,
            'tranthibinh_passport.pdf',
            'Hộ chiếu Trần Thị Bình',
            'local',
            'documents',
            'residents/tranthibinh_passport.pdf',
            'application/pdf',
            'pdf',
            512000,
            'ready',
            'private',
            admin_user_id,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            file_3_id,
            'levancuong_id_card.jpg',
            'CMND Lê Văn Cường',
            'local',
            'documents',
            'residents/levancuong_id_card.jpg',
            'image/jpeg',
            'jpg',
            192000,
            'ready',
            'private',
            admin_user_id,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            file_4_id,
            'phamthidung_household.pdf',
            'Sổ hộ khẩu Phạm Thị Dung',
            'local',
            'documents',
            'residents/phamthidung_household.pdf',
            'application/pdf',
            'pdf',
            1024000,
            'ready',
            'private',
            admin_user_id,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            file_5_id,
            'hoangvanem_temporary_residence.pdf',
            'Giấy tạm trú Hoàng Văn Em',
            'local',
            'documents',
            'residents/hoangvanem_temporary_residence.pdf',
            'application/pdf',
            'pdf',
            128000,
            'ready',
            'private',
            admin_user_id,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            file_6_id,
            'nguyenvanan_contract.pdf',
            'Hợp đồng Nguyễn Văn An',
            'local',
            'documents',
            'residents/nguyenvanan_contract.pdf',
            'application/pdf',
            'pdf',
            256000,
            'ready',
            'private',
            admin_user_id,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        )
    ON CONFLICT (id) DO NOTHING;

    -- ─────────────────────────────────────────────────────────────
    -- Section 5: Seed Resident Documents
    -- ─────────────────────────────────────────────────────────────

    INSERT INTO resident_documents (
        id,
        resident_id,
        file_id,
        document_type,
        document_name,
        description,
        is_primary,
        issued_date,
        expiry_date,
        created_by,
        updated_by,
        created_at,
        updated_at
    ) VALUES
        (
            '00000001-0001-0001-0001-000000000040',
            resident_1_id,
            file_1_id,
            'id_card',
            'CCCD Nguyễn Văn An',
            'Căn cước công dân mặt trước',
            TRUE,
            '2020-01-15',
            '2035-01-15',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000041',
            resident_1_id,
            file_6_id,
            'contract',
            'Hợp đồng thuê phòng',
            'Hợp đồng thuê phòng A101',
            FALSE,
            '2024-01-15',
            '2025-01-15',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000042',
            resident_2_id,
            file_2_id,
            'passport',
            'Hộ chiếu Trần Thị Bình',
            'Hộ chiếu phổ thông',
            TRUE,
            '2018-08-20',
            '2028-08-20',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000043',
            resident_3_id,
            file_3_id,
            'id_card',
            'CMND Lê Văn Cường',
            'Chứng minh nhân dân',
            TRUE,
            '2010-12-10',
            '2025-12-10',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000044',
            resident_4_id,
            file_4_id,
            'household_registration',
            'Sổ hộ khẩu Phạm Thị Dung',
            'Sổ hộ khẩu TP.HCM',
            TRUE,
            '2015-03-25',
            NULL,
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000045',
            resident_5_id,
            file_5_id,
            'temporary_residence',
            'Giấy tạm trú Hoàng Văn Em',
            'Giấy khai báo tạm trú',
            TRUE,
            '2022-01-10',
            '2023-01-10',
            admin_user_id,
            admin_user_id,
            CURRENT_TIMESTAMP,
            CURRENT_TIMESTAMP
        )
    ON CONFLICT (id) DO NOTHING;

    -- ─────────────────────────────────────────────────────────────
    -- Section 6: Seed Resident Events (audit/lifecycle tracking)
    -- ─────────────────────────────────────────────────────────────

    INSERT INTO resident_events (
        id,
        resident_id,
        event_type,
        payload,
        correlation_id,
        created_by,
        created_at
    ) VALUES
        (
            '00000001-0001-0001-0001-000000000050',
            resident_1_id,
            'created',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'full_name', 'Nguyễn Văn An',
                    'email', 'nguyenvanan@example.com',
                    'phone', '+84901234567'
                ),
                'metadata', jsonb_build_object(
                    'created_at', to_jsonb(CURRENT_TIMESTAMP)
                ),
                'reason', 'New resident registration'
            ),
            NULL,
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000051',
            resident_1_id,
            'moved_in',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'bed_id', bed_101_1_id,
                    'move_in_at', '2024-01-15'
                ),
                'metadata', jsonb_build_object(
                    'stay_id', '00000001-0001-0001-0001-000000000024'
                ),
                'reason', 'Initial move-in to bed 101-1'
            ),
            '00000001-0001-0001-0001-000000000024',
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000052',
            resident_2_id,
            'created',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'full_name', 'Trần Thị Bình',
                    'email', 'tranthibinh@example.com',
                    'phone', '+84903456789'
                ),
                'metadata', jsonb_build_object(
                    'created_at', to_jsonb(CURRENT_TIMESTAMP)
                ),
                'reason', 'New resident registration'
            ),
            NULL,
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000053',
            resident_2_id,
            'moved_in',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'bed_id', bed_102_1_id,
                    'move_in_at', '2024-02-01'
                ),
                'metadata', jsonb_build_object(
                    'stay_id', '00000001-0001-0001-0001-000000000025'
                ),
                'reason', 'Initial move-in to bed 102-1'
            ),
            '00000001-0001-0001-0001-000000000025',
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000054',
            resident_3_id,
            'created',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'full_name', 'Lê Văn Cường',
                    'email', 'levancuong@example.com',
                    'phone', '+84904567891'
                ),
                'metadata', jsonb_build_object(
                    'created_at', to_jsonb(CURRENT_TIMESTAMP)
                ),
                'reason', 'New resident registration'
            ),
            NULL,
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000055',
            resident_3_id,
            'moved_in',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'bed_id', bed_201_1_id,
                    'move_in_at', '2023-06-15'
                ),
                'metadata', jsonb_build_object(
                    'stay_id', '00000001-0001-0001-0001-000000000026'
                ),
                'reason', 'Initial move-in to bed 201-1'
            ),
            '00000001-0001-0001-0001-000000000026',
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000056',
            resident_4_id,
            'created',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'full_name', 'Phạm Thị Dung',
                    'email', 'phamthidung@example.com',
                    'phone', '+84905678902'
                ),
                'metadata', jsonb_build_object(
                    'created_at', to_jsonb(CURRENT_TIMESTAMP)
                ),
                'reason', 'New resident registration'
            ),
            NULL,
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000057',
            resident_4_id,
            'status_changed',
            jsonb_build_object(
                'before', jsonb_build_object(
                    'status', 'active'
                ),
                'after', jsonb_build_object(
                    'status', 'inactive'
                ),
                'metadata', jsonb_build_object(
                    'changed_at', to_jsonb(CURRENT_TIMESTAMP)
                ),
                'reason', 'Resident marked as inactive'
            ),
            NULL,
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000058',
            resident_5_id,
            'created',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'full_name', 'Hoàng Văn Em',
                    'email', 'hoangvanem@example.com',
                    'phone', '+84907890123'
                ),
                'metadata', jsonb_build_object(
                    'created_at', to_jsonb(CURRENT_TIMESTAMP)
                ),
                'reason', 'New resident registration'
            ),
            NULL,
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000059',
            resident_5_id,
            'moved_in',
            jsonb_build_object(
                'after', jsonb_build_object(
                    'bed_id', bed_301_1_id,
                    'move_in_at', '2022-01-10'
                ),
                'metadata', jsonb_build_object(
                    'stay_id', '00000001-0001-0001-0001-000000000028'
                ),
                'reason', 'Initial move-in to bed 301-1'
            ),
            '00000001-0001-0001-0001-000000000028',
            admin_user_id,
            CURRENT_TIMESTAMP
        ),
        (
            '00000001-0001-0001-0001-000000000060',
            resident_5_id,
            'moved_out',
            jsonb_build_object(
                'before', jsonb_build_object(
                    'bed_id', bed_301_1_id,
                    'move_in_at', '2022-01-10'
                ),
                'after', jsonb_build_object(
                    'move_out_at', '2023-12-15',
                    'move_out_reason', 'Contract ended'
                ),
                'metadata', jsonb_build_object(
                    'stay_id', '00000001-0001-0001-0001-000000000028'
                ),
                'reason', 'Resident moved out - contract ended'
            ),
            '00000001-0001-0001-0001-000000000028',
            admin_user_id,
            CURRENT_TIMESTAMP
        )
    ON CONFLICT DO NOTHING;

    RAISE NOTICE 'Resident seed completed successfully';
END $$;
