CREATE TABLE IF NOT EXISTS document_templates (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  document_type ENUM('ticket','receipt','invoice','quote','membership_id','membership_certificate','event_certificate','event_nametag') NOT NULL,
  name VARCHAR(160) NOT NULL,
  page_format VARCHAR(30) NOT NULL DEFAULT 'A4',
  orientation ENUM('P','L') NOT NULL DEFAULT 'P',
  header_image_url VARCHAR(1000) NULL,
  footer_image_url VARCHAR(1000) NULL,
  template_html MEDIUMTEXT NOT NULL,
  custom_css MEDIUMTEXT NULL,
  is_default TINYINT(1) NOT NULL DEFAULT 0,
  is_active TINYINT(1) NOT NULL DEFAULT 1,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_document_template_type (document_type, is_active, is_default)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
