-- Function to create default customer for new organization
CREATE OR REPLACE FUNCTION create_default_customer()
RETURNS TRIGGER AS $$
BEGIN
    INSERT INTO customers (organization_id, name, is_default, is_active, created_at, updated_at)
    VALUES (NEW.id, 'Walk In Customer', true, true, NOW(), NOW());
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Trigger to automatically create default customer when organization is created
CREATE TRIGGER trigger_create_default_customer
    AFTER INSERT ON organizations
    FOR EACH ROW
    EXECUTE FUNCTION create_default_customer(); 