-- Ether业主小程序测试数据 - MDM服务
-- PostgreSQL语法 - 根据实际表结构

-- 清理旧测试数据
DELETE FROM mdm_family_member WHERE owner_id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';
DELETE FROM mdm_visitor_appointment WHERE appointment_no LIKE 'VA%';
DELETE FROM mdm_ownership WHERE owner_id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';
DELETE FROM mdm_owner WHERE id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';

-- 插入测试业主
INSERT INTO mdm_owner (id, owner_no, name, phone, id_card, owner_type, status, gender, project_id, created_at, updated_at) VALUES
('b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'O2024001', '张三', '13800138001', '110101199001011234', 'INDIVIDUAL', 'ACTIVE', 'MALE', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', NOW(), NOW());

-- 插入测试房产关联
INSERT INTO mdm_ownership (id, project_id, space_node_id, owner_id, owner_name, ownership_type, status, is_primary, created_at, updated_at) VALUES
('c9357f9a-1e11-45e4-b3a6-f2447bdde1a8', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'e9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '张三', 'OWNER', 'ACTIVE', true, NOW(), NOW());

-- 插入测试访客预约
INSERT INTO mdm_visitor_appointment (id, appointment_no, visitor_name, visitor_phone, visitor_type, visit_purpose, visit_date, expected_arrival_time, booker_id, host_owner_id, host_address, status, project_id, created_at, updated_at) VALUES
('f9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'VA2024001', '李四', '13900139001', 'FAMILY', 'VISIT', CURRENT_DATE + INTERVAL '1 day', '10:00:00', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '1栋1单元101', 'APPROVED', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', NOW(), NOW()),
('f9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'VA2024002', '王五', '13900139002', 'DELIVERY', 'DELIVERY', CURRENT_DATE, '14:00:00', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '1栋1单元101', 'CHECKED_IN', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', NOW(), NOW());

-- 插入测试家庭成员
INSERT INTO mdm_family_member (id, owner_id, name, phone, relation, status, created_at, updated_at) VALUES
('c9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '张三妻子', '13800138002', 'SPOUSE', 'ACTIVE', NOW(), NOW()),
('c9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '张三儿子', '13800138003', 'CHILD', 'ACTIVE', NOW(), NOW());

SELECT 'MDM测试数据插入完成' AS result;
