-- Fix duplicate membership statuses
-- The database has both "Active" (capitalized name) and "active" (lowercase) entries.
-- The seed data only creates "active" - the "Active" entry was added manually.
-- We need to:
-- 1. Move any members pointing to the duplicate "Active" status to the original "active" status
-- 2. Delete the duplicate "Active" entry

-- First, update any members that reference the duplicate "Active" (capitalized) status
-- to point to the original "active" (lowercase) status
UPDATE public.members
SET membership_status_id = (
  SELECT id FROM public.membership_statuses WHERE name = 'active' LIMIT 1
)
WHERE membership_status_id IN (
  SELECT id FROM public.membership_statuses WHERE name = 'Active'
);

-- Delete the duplicate "Active" (capitalized) status entry
DELETE FROM public.membership_statuses WHERE name = 'Active';

-- Ensure the remaining "active" status has correct sort_order
UPDATE public.membership_statuses
SET sort_order = 2, display_name = 'Active', color = '#22c55e'
WHERE name = 'active';
