-- Add missing email_parser_agents table
CREATE TABLE IF NOT EXISTS `email_parser_agents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `agency_id` bigint unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `provider` varchar(50) DEFAULT 'imap',
  `host` varchar(255) DEFAULT '',
  `port` int DEFAULT 993,
  `username` varchar(255) DEFAULT '',
  `password` varchar(255) DEFAULT '',
  `use_ssl` tinyint(1) DEFAULT 1,
  `is_active` tinyint(1) DEFAULT 1,
  `last_sync` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `agency_id` (`agency_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Update email_parser_settings to match the expected columns
ALTER TABLE `email_parser_settings` 
  ADD COLUMN IF NOT EXISTS `folder_to_watch` varchar(100) DEFAULT 'INBOX' AFTER `imap_folder`,
  ADD COLUMN IF NOT EXISTS `auto_create_bookings` tinyint(1) DEFAULT 0 AFTER `folder_to_watch`;
