CREATE TABLE IF NOT EXISTS `customer_applications` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`application_id` VARCHAR(255) NOT NULL UNIQUE,
`customer_id` VARCHAR(255) NULL,
`company_name` VARCHAR(255) NOT NULL,
`company_website` VARCHAR(255) NULL,
`company_phone` VARCHAR(255) NULL,
`sales_owner` VARCHAR(255) NOT NULL,
`payment_terms` VARCHAR(255) NOT NULL,
`tags` TEXT NULL,
`notes` TEXT NULL,
`status` VARCHAR(50) NOT NULL DEFAULT 'DRAFT',
`created_by` VARCHAR(255) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `customer_contacts` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`customer_application_id` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`phone` VARCHAR(255) NULL,
`is_primary` BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `customer_addresses` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`customer_application_id` INT NOT NULL,
`address_type` VARCHAR(50) NOT NULL, -- e.g., 'BILLING', 'SHIPPING'
`address_line_1` VARCHAR(255) NOT NULL,
`address_line_2` VARCHAR(255) NULL,
`city` VARCHAR(255) NOT NULL,
`state` VARCHAR(255) NOT NULL,
`postal_code` VARCHAR(50) NOT NULL,
`country` VARCHAR(100) NOT NULL,
FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;