<?php

namespace Battles\Admin;

use Battles\Database\Db;

class Item
{
    public static function add(array $params): void
    {
        $query = 'insert into items (
                   name, item_type, durability, 
                   need_strength, need_dexterity, need_intuition, need_endurance, need_intelligence, need_wisdom, 
                   add_strength, add_dexterity, add_intuition, add_endurance, add_intelligence, add_wisdom, 
                   add_accuracy, add_evasion, add_criticals, add_min_physical_damage, add_max_physical_damage, 
                   image, weight) 
                values (
                    :name, :item_type, :durability, 
                    :need_strength, :need_dexterity, :need_intuition, :need_endurance, :need_intelligence, :need_wisdom, 
                    :add_strength, :add_dexterity, :add_intuition, :add_endurance, :add_intelligence, :add_wisdom, 
                    :add_accuracy, :add_evasion, :add_criticals, :add_min_physical_damage, :add_max_physical_damage, 
                    :image, :weight)';
        $values = [
            'name' => $params['name'] ?? uniqid(),
            'item_type' => $params['item_type'],
            'durability' => $params['durability'] ?? 1,
            'need_strength' => $params['need_strength'] ?? 0,
            'need_dexterity' => $params['need_dexterity'] ?? 0,
            'need_intuition' => $params['need_intuition'] ?? 0,
            'need_endurance' => $params['need_endurance'] ?? 0,
            'need_intelligence' => $params['need_intelligence'] ?? 0,
            'need_wisdom' => $params['need_wisdom'] ?? 0,
            'add_strength' => $params['add_strength'] ?? 0,
            'add_dexterity' => $params['add_dexterity'] ?? 0,
            'add_intuition' => $params['add_intuition'] ?? 0,
            'add_endurance' => $params['add_endurance'] ?? 0,
            'add_intelligence' => $params['add_intelligence'] ?? 0,
            'add_wisdom' => $params['add_wisdom'] ?? 0,
            'add_accuracy' => $params['add_accuracy'] ?? 0,
            'add_evasion' => $params['add_evasion'] ?? 0,
            'add_criticals' => $params['add_criticals'] ?? 0,
            'add_min_physical_damage' => $params['add_min_physical_damage'] ?? 0,
            'add_max_physical_damage' => $params['add_max_physical_damage'] ?? 0,
            'image' => $params['image'] ?? 'noitem.png',
            'weight' => $params['weight'] ?? 1,
        ];
        Db::getInstance()->execute($query, $values);
    }
}