
CREATE DATABASE IF NOT EXISTS redirector_mvp;
USE redirector_mvp;

CREATE TABLE domains (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  is_active BOOLEAN DEFAULT 1,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE short_links (
  id INT AUTO_INCREMENT PRIMARY KEY,
  domain_id INT,
  slug VARCHAR(255) UNIQUE NOT NULL,
  redirect_type ENUM('direct', 'confirmation') DEFAULT 'direct',
  utm_config JSON,
  pixel_data JSON,
  is_abtest BOOLEAN DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (domain_id) REFERENCES domains(id)
);

CREATE TABLE link_destinations (
  id INT AUTO_INCREMENT PRIMARY KEY,
  short_link_id INT,
  url TEXT NOT NULL,
  weight INT DEFAULT 100,
  conversion_goal VARCHAR(255),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (short_link_id) REFERENCES short_links(id)
);
