-- 2026_02_04_add_engagement_features.sql
-- Favoriler, karşılaştırma ve görüntülenme sayacı için gerekli tablolar

ALTER TABLE properties
  ADD COLUMN views INT NOT NULL DEFAULT 0;

CREATE TABLE IF NOT EXISTS property_views (
  id INT AUTO_INCREMENT PRIMARY KEY,
  property_id INT NOT NULL,
  session_id VARCHAR(128) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_view (property_id, session_id),
  KEY idx_view_session (session_id),
  CONSTRAINT fk_view_property FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS property_favorites (
  id INT AUTO_INCREMENT PRIMARY KEY,
  property_id INT NOT NULL,
  session_id VARCHAR(128) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_fav (property_id, session_id),
  KEY idx_fav_session (session_id),
  CONSTRAINT fk_fav_property FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS property_compares (
  id INT AUTO_INCREMENT PRIMARY KEY,
  property_id INT NOT NULL,
  session_id VARCHAR(128) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_cmp (property_id, session_id),
  KEY idx_cmp_session (session_id),
  CONSTRAINT fk_cmp_property FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
