-- DB update 2026_04_12_00 -> 2026_05_15_00
--
CREATE TABLE lost_corpses (
    lost_corpse_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    player_guid BIGINT UNSIGNED NOT NULL,
    corpse_guid BIGINT UNSIGNED NULL,
    map_id SMALLINT UNSIGNED NOT NULL,
    zone_id SMALLINT UNSIGNED NOT NULL,
    position_x FLOAT NOT NULL,
    position_y FLOAT NOT NULL,
    position_z FLOAT NOT NULL,
    orientation FLOAT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    money BIGINT UNSIGNED DEFAULT 0,
    active TINYINT(1) NOT NULL DEFAULT 1,

    INDEX idx_player_guid (player_guid),
    INDEX idx_corpse_guid (corpse_guid),
    INDEX idx_map_zone (map_id, zone_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE lost_corpse_items (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    lost_corpse_id BIGINT UNSIGNED NOT NULL,
    item_entry INT UNSIGNED NOT NULL,
    count INT UNSIGNED NOT NULL DEFAULT 1,
    randomPropertyId INT DEFAULT 0,
    durability INT UNSIGNED DEFAULT 0,
    enchantments TEXT,
    looted TINYINT(1) NOT NULL DEFAULT 0,

    CONSTRAINT fk_lost_corpse
        FOREIGN KEY (lost_corpse_id)
        REFERENCES lost_corpses(lost_corpse_id)
        ON DELETE CASCADE,

    INDEX idx_lost_corpse_id (lost_corpse_id),
    INDEX idx_item_entry (item_entry)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE lost_corpses
ADD UNIQUE KEY uniq_lookup (player_guid, corpse_guid, created_at);

ALTER TABLE lost_corpses 
ADD COLUMN money_collected TINYINT(1) NOT NULL DEFAULT 0;
