-- ============================================================================
-- CT NAILS — Migration 002: contact_messages (Phase 2)
-- Run after schema.sql + seed.sql:
--   mysql -u <user> -p <database> < database/migrations/002_contact_messages.sql
-- Stores messages sent from the public Contact page (contact.php).
-- Admin reads / replies to them from the dashboard (Phase 5).
-- No email is sent automatically in Phase 2 — SMTP is wired in Phase 4/6.
-- ============================================================================

CREATE TABLE IF NOT EXISTS `contact_messages` (
  `id`         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name`       VARCHAR(100)    NOT NULL,
  `email`      VARCHAR(191)    NOT NULL,
  `phone`      VARCHAR(20)     NULL DEFAULT NULL,
  `subject`    VARCHAR(150)    NULL DEFAULT NULL,
  `message`    TEXT            NOT NULL,
  `status`     ENUM('new','read','replied') NOT NULL DEFAULT 'new',
  `ip_address` VARCHAR(45)     NULL DEFAULT NULL,
  `created_at` TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  INDEX `idx_contact_status` (`status`),
  INDEX `idx_contact_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  COMMENT='Messages from the public contact form';
