-- Monzer final requested fixes - run once if your DB is missing these columns
ALTER TABLE campaign ADD COLUMN IF NOT EXISTS is_sent TINYINT(1) NOT NULL DEFAULT 0;
ALTER TABLE campaign ADD COLUMN IF NOT EXISTS sent_at DATETIME NULL;
ALTER TABLE campaign ADD COLUMN IF NOT EXISTS sent_by INT NULL;
ALTER TABLE campaign ADD COLUMN IF NOT EXISTS customer_count INT NOT NULL DEFAULT 0;
ALTER TABLE audience ADD COLUMN IF NOT EXISTS customer_count INT NOT NULL DEFAULT 0;
ALTER TABLE communications ADD COLUMN IF NOT EXISTS campaign_id INT NULL;
ALTER TABLE communications ADD COLUMN IF NOT EXISTS source_type VARCHAR(30) NOT NULL DEFAULT 'direct';
CREATE TABLE IF NOT EXISTS quotation_items (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  quotation_id INT NOT NULL,
  item_id INT NOT NULL,
  quantity INT NOT NULL DEFAULT 1,
  unit_price DECIMAL(12,2) NOT NULL DEFAULT 0,
  line_total DECIMAL(12,2) NOT NULL DEFAULT 0,
  date_created DATETIME DEFAULT CURRENT_TIMESTAMP,
  KEY idx_quotation_items_q (quotation_id),
  KEY idx_quotation_items_item (item_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
