-- Create members table
CREATE TABLE members (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL,
    email VARCHAR(255) UNIQUE,
    phone VARCHAR(20),
    address TEXT,
    date_of_birth DATE,
    membership_status VARCHAR(20) DEFAULT 'active' CHECK (membership_status IN ('active', 'inactive', 'transferred', 'deceased')),
    join_date DATE,
    baptism_date DATE,
    notes TEXT,
    emergency_contact_name VARCHAR(200),
    emergency_contact_phone VARCHAR(20),
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create indexes
CREATE INDEX idx_members_name ON members(last_name, first_name);
CREATE INDEX idx_members_email ON members(email);
CREATE INDEX idx_members_status ON members(membership_status);
CREATE INDEX idx_members_join_date ON members(join_date);

-- Insert sample members for testing
INSERT INTO members (first_name, last_name, email, phone, membership_status, join_date) VALUES 
('John', 'Doe', 'john.doe@example.com', '555-0123', 'active', '2020-01-15'),
('Jane', 'Smith', 'jane.smith@example.com', '555-0124', 'active', '2019-05-20'),
('Robert', 'Johnson', 'robert.johnson@example.com', '555-0125', 'active', '2021-03-10'),
('Mary', 'Williams', 'mary.williams@example.com', '555-0126', 'inactive', '2018-11-05'),
('David', 'Brown', 'david.brown@example.com', '555-0127', 'active', '2022-08-14');