ALTER TABLE whatsapp_config
    ADD COLUMN IF NOT EXISTS integration_mode VARCHAR(20) NOT NULL DEFAULT 'waychat' AFTER provider_name,
    ADD COLUMN IF NOT EXISTS company_auth_token VARCHAR(255) NULL AFTER auth_token,
    ADD COLUMN IF NOT EXISTS waychat_base_url VARCHAR(255) NOT NULL DEFAULT 'https://waychat.app.br' AFTER webhook_token,
    ADD COLUMN IF NOT EXISTS waychat_connection_type VARCHAR(20) NOT NULL DEFAULT 'cloud' AFTER waychat_base_url,
    ADD COLUMN IF NOT EXISTS waychat_send_mode VARCHAR(20) NOT NULL DEFAULT 'message' AFTER waychat_connection_type,
    ADD COLUMN IF NOT EXISTS waychat_template_name VARCHAR(120) NULL AFTER waychat_send_mode,
    ADD COLUMN IF NOT EXISTS waychat_template_language VARCHAR(20) NOT NULL DEFAULT 'pt_BR' AFTER waychat_template_name,
    ADD COLUMN IF NOT EXISTS waychat_create_deal TINYINT(1) NOT NULL DEFAULT 0 AFTER waychat_template_language,
    ADD COLUMN IF NOT EXISTS waychat_sector_name VARCHAR(120) NULL AFTER waychat_create_deal,
    ADD COLUMN IF NOT EXISTS waychat_column_name VARCHAR(120) NULL AFTER waychat_sector_name,
    ADD COLUMN IF NOT EXISTS waychat_status_on_send VARCHAR(20) NULL AFTER waychat_column_name;

UPDATE whatsapp_config
SET integration_mode = COALESCE(NULLIF(integration_mode, ''), 'waychat'),
    waychat_base_url = COALESCE(NULLIF(waychat_base_url, ''), 'https://waychat.app.br'),
    waychat_connection_type = COALESCE(NULLIF(waychat_connection_type, ''), 'cloud'),
    waychat_send_mode = COALESCE(NULLIF(waychat_send_mode, ''), 'message'),
    waychat_template_language = COALESCE(NULLIF(waychat_template_language, ''), 'pt_BR');
