-- Seed lookup data for HoneyDue
-- Run with: ./dev.sh seed

-- Residence Types (only has: id, created_at, updated_at, name)
-- Ordered A-Z by name
INSERT INTO residence_residencetype (id, created_at, updated_at, name)
VALUES
    (1, NOW(), NOW(), 'Apartment'),
    (2, NOW(), NOW(), 'Condo'),
    (3, NOW(), NOW(), 'Duplex'),
    (4, NOW(), NOW(), 'House'),
    (5, NOW(), NOW(), 'Mobile Home'),
    (6, NOW(), NOW(), 'Other'),
    (7, NOW(), NOW(), 'Townhouse'),
    (8, NOW(), NOW(), 'Vacation Home')
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    updated_at = NOW();

-- Task Categories (has: name, description, icon, color, display_order)
-- Ordered A-Z by name with display_order matching
INSERT INTO task_taskcategory (id, created_at, updated_at, name, description, icon, color, display_order)
VALUES
    (1, NOW(), NOW(), 'Appliances', 'Appliance maintenance and repair', 'cog', '#9b59b6', 1),
    (2, NOW(), NOW(), 'Cleaning', 'Cleaning and sanitation', 'broom', '#1abc9c', 2),
    (3, NOW(), NOW(), 'Electrical', 'Electrical work and repairs', 'bolt', '#f1c40f', 3),
    (4, NOW(), NOW(), 'Exterior', 'Exterior maintenance and landscaping', 'tree', '#27ae60', 4),
    (5, NOW(), NOW(), 'General', 'General maintenance tasks', 'tools', '#7f8c8d', 5),
    (6, NOW(), NOW(), 'HVAC', 'Heating, ventilation, and air conditioning', 'thermometer', '#e74c3c', 6),
    (7, NOW(), NOW(), 'Interior', 'Interior maintenance and repairs', 'home', '#e67e22', 7),
    (8, NOW(), NOW(), 'Pest Control', 'Pest prevention and control', 'bug', '#8e44ad', 8),
    (9, NOW(), NOW(), 'Plumbing', 'Plumbing related tasks', 'wrench', '#3498db', 9),
    (10, NOW(), NOW(), 'Safety', 'Safety and security tasks', 'shield', '#c0392b', 10)
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    description = EXCLUDED.description,
    icon = EXCLUDED.icon,
    color = EXCLUDED.color,
    display_order = EXCLUDED.display_order,
    updated_at = NOW();

-- Task Priorities (has: name, level, color, display_order - NO description)
INSERT INTO task_taskpriority (id, created_at, updated_at, name, level, color, display_order)
VALUES
    (1, NOW(), NOW(), 'Low', 1, '#27ae60', 1),
    (2, NOW(), NOW(), 'Medium', 2, '#f39c12', 2),
    (3, NOW(), NOW(), 'High', 3, '#e74c3c', 3),
    (4, NOW(), NOW(), 'Urgent', 4, '#c0392b', 4)
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    level = EXCLUDED.level,
    color = EXCLUDED.color,
    display_order = EXCLUDED.display_order,
    updated_at = NOW();

-- NOTE: task_taskstatus table removed - replaced with in_progress boolean field on task_task

-- Task Frequencies (has: name, days, display_order)
INSERT INTO task_taskfrequency (id, created_at, updated_at, name, days, display_order)
VALUES
    (1, NOW(), NOW(), 'Once', NULL, 1),
    (2, NOW(), NOW(), 'Daily', 1, 2),
    (3, NOW(), NOW(), 'Weekly', 7, 3),
    (4, NOW(), NOW(), 'Bi-Weekly', 14, 4),
    (5, NOW(), NOW(), 'Monthly', 30, 5),
    (6, NOW(), NOW(), 'Quarterly', 90, 6),
    (7, NOW(), NOW(), 'Semi-Annually', 180, 7),
    (8, NOW(), NOW(), 'Annually', 365, 8),
    (9, NOW(), NOW(), 'Custom', NULL, 9)
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    days = EXCLUDED.days,
    display_order = EXCLUDED.display_order,
    updated_at = NOW();

-- Contractor Specialties (has: name, description, icon, display_order)
-- Ordered A-Z by name with display_order matching
INSERT INTO task_contractorspecialty (id, created_at, updated_at, name, display_order)
VALUES
    (1, NOW(), NOW(), 'Appliance Repair', 1),
    (2, NOW(), NOW(), 'Carpenter', 2),
    (3, NOW(), NOW(), 'Cleaner', 3),
    (4, NOW(), NOW(), 'Electrician', 4),
    (5, NOW(), NOW(), 'General Contractor', 5),
    (6, NOW(), NOW(), 'Handyman', 6),
    (7, NOW(), NOW(), 'HVAC Technician', 7),
    (8, NOW(), NOW(), 'Landscaper', 8),
    (9, NOW(), NOW(), 'Locksmith', 9),
    (10, NOW(), NOW(), 'Painter', 10),
    (11, NOW(), NOW(), 'Pest Control', 11),
    (12, NOW(), NOW(), 'Plumber', 12),
    (13, NOW(), NOW(), 'Pool Service', 13),
    (14, NOW(), NOW(), 'Roofer', 14)
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    display_order = EXCLUDED.display_order,
    updated_at = NOW();

-- Subscription Settings (singleton)
INSERT INTO subscription_subscriptionsettings (id, enable_limitations)
VALUES (1, false)
ON CONFLICT (id) DO NOTHING;

-- Tier Limits
INSERT INTO subscription_tierlimits (id, created_at, updated_at, tier, properties_limit, tasks_limit, contractors_limit, documents_limit)
VALUES
    (1, NOW(), NOW(), 'free', 1, 10, 0, 0),
    (2, NOW(), NOW(), 'pro', NULL, NULL, NULL, NULL)
ON CONFLICT (id) DO UPDATE SET
    tier = EXCLUDED.tier,
    properties_limit = EXCLUDED.properties_limit,
    tasks_limit = EXCLUDED.tasks_limit,
    contractors_limit = EXCLUDED.contractors_limit,
    documents_limit = EXCLUDED.documents_limit,
    updated_at = NOW();

-- Feature Benefits
INSERT INTO subscription_featurebenefit (id, created_at, updated_at, feature_name, free_tier_text, pro_tier_text, display_order, is_active)
VALUES
    (1, NOW(), NOW(), 'Properties', '1 property', 'Unlimited properties', 1, true),
    (2, NOW(), NOW(), 'Tasks', '10 tasks', 'Unlimited tasks', 2, true),
    (3, NOW(), NOW(), 'Contractors', 'Not available', 'Unlimited contractors', 3, true),
    (4, NOW(), NOW(), 'Documents', 'Not available', 'Unlimited documents', 4, true),
    (5, NOW(), NOW(), 'PDF Reports', 'Not available', 'Generate PDF reports', 5, true),
    (6, NOW(), NOW(), 'Priority Support', 'Community support', 'Priority email support', 6, true)
ON CONFLICT (id) DO UPDATE SET
    feature_name = EXCLUDED.feature_name,
    free_tier_text = EXCLUDED.free_tier_text,
    pro_tier_text = EXCLUDED.pro_tier_text,
    display_order = EXCLUDED.display_order,
    is_active = EXCLUDED.is_active,
    updated_at = NOW();

-- Upgrade Triggers
INSERT INTO subscription_upgradetrigger (id, created_at, updated_at, trigger_key, title, message, button_text, is_active)
VALUES
    (1, NOW(), NOW(), 'property_limit', 'Upgrade to Add More Properties', 'You''ve reached the free tier limit of 1 property. Upgrade to Pro to add unlimited properties.', 'Upgrade to Pro', true),
    (2, NOW(), NOW(), 'task_limit', 'Upgrade for More Tasks', 'You''ve reached the free tier limit of 10 tasks. Upgrade to Pro for unlimited tasks.', 'Upgrade to Pro', true),
    (3, NOW(), NOW(), 'contractor_access', 'Unlock Contractor Management', 'Contractor management is a Pro feature. Upgrade to keep track of your service providers.', 'Upgrade to Pro', true),
    (4, NOW(), NOW(), 'document_access', 'Unlock Document Storage', 'Document storage is a Pro feature. Upgrade to store warranties, manuals, and more.', 'Upgrade to Pro', true)
ON CONFLICT (id) DO UPDATE SET
    trigger_key = EXCLUDED.trigger_key,
    title = EXCLUDED.title,
    message = EXCLUDED.message,
    button_text = EXCLUDED.button_text,
    is_active = EXCLUDED.is_active,
    updated_at = NOW();

-- Reset sequences to max id + 1
SELECT setval('residence_residencetype_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM residence_residencetype), false);
SELECT setval('task_taskcategory_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM task_taskcategory), false);
SELECT setval('task_taskpriority_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM task_taskpriority), false);
SELECT setval('task_taskfrequency_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM task_taskfrequency), false);
SELECT setval('task_contractorspecialty_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM task_contractorspecialty), false);
SELECT setval('subscription_tierlimits_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM subscription_tierlimits), false);
SELECT setval('subscription_featurebenefit_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM subscription_featurebenefit), false);
SELECT setval('subscription_upgradetrigger_id_seq', (SELECT COALESCE(MAX(id), 0) + 1 FROM subscription_upgradetrigger), false);
