-- Fraktionskasse
CREATE TABLE IF NOT EXISTS `mercyv_faction_treasury` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `faction_id` VARCHAR(50) NOT NULL UNIQUE,
    `balance_money` INT NOT NULL DEFAULT 0,
    `balance_black_money` INT NOT NULL DEFAULT 0,
    `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Transaktionslog
CREATE TABLE IF NOT EXISTS `mercyv_faction_transactions` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `faction_id` VARCHAR(50) NOT NULL,
    `player_identifier` VARCHAR(60) NOT NULL,
    `player_name` VARCHAR(100) NOT NULL,
    `type` ENUM('deposit', 'withdraw') NOT NULL,
    `account_type` ENUM('money', 'black_money') NOT NULL,
    `amount` INT NOT NULL,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_faction` (`faction_id`),
    INDEX `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Rechte-Overrides pro Fraktion (vom Boss gesetzt)
CREATE TABLE IF NOT EXISTS `mercyv_faction_permissions` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `faction_id` VARCHAR(50) NOT NULL,
    `permission_key` VARCHAR(50) NOT NULL,
    `min_grade` INT NOT NULL DEFAULT 0,
    UNIQUE KEY `uq_faction_perm` (`faction_id`, `permission_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
