-- Tournament War System Table
-- Tracks federation vs federation battles and points scoring

CREATE TABLE `tournament_war` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tournament_id` int(11) NOT NULL DEFAULT 0,
  `datetime` datetime NOT NULL,
  `attacker_id` int(11) NOT NULL,
  `attacker_fed` int(11) NOT NULL,
  `defender_id` int(11) NOT NULL,
  `defender_fed` int(11) NOT NULL,
  `attack_result` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1=attacker wins, 0=defender wins',
  `colonies_won` int(11) NOT NULL DEFAULT 0 COMMENT 'Number of colonies captured',
  `attacker_points` int(11) NOT NULL DEFAULT 0,
  `defender_points` int(11) NOT NULL DEFAULT 0,
  `event_attack_id` int(11) DEFAULT NULL COMMENT 'Reference to original event_attack record',
  PRIMARY KEY (`id`),
  KEY `idx_tournament_fed` (`tournament_id`, `attacker_fed`, `defender_fed`),
  KEY `idx_datetime` (`datetime`),
  KEY `idx_event_attack` (`event_attack_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;

-- Server Settings for Tournament War Point Values
INSERT INTO `server_settings` (`setting_key`, `setting_value`, `updated_by`) VALUES
('war_points_attack_1col', '10', 0),
('war_points_attack_2col', '25', 0),
('war_points_attack_3col', '50', 0),
('war_points_defense_win', '15', 0),
('war_points_attack_loss', '0', 0);