-- Superfax HelpDesk - Upgrade Prontuário Equipamentos V2
-- Execute no banco usado pelo sistema, por exemplo: suporte

ALTER TABLE equipment
  ADD COLUMN IF NOT EXISTS ip_address VARCHAR(80) NULL,
  ADD COLUMN IF NOT EXISTS mac_address VARCHAR(80) NULL,
  ADD COLUMN IF NOT EXISTS installed_at DATE NULL,
  ADD COLUMN IF NOT EXISTS warranty_until DATE NULL,
  ADD COLUMN IF NOT EXISTS last_maintenance_at DATE NULL,
  ADD COLUMN IF NOT EXISTS contract_id INT NULL;

CREATE TABLE IF NOT EXISTS maintenance_history (
  id INT AUTO_INCREMENT PRIMARY KEY,
  equipment_id INT NOT NULL,
  type VARCHAR(120) DEFAULT 'Manutenção',
  description TEXT NULL,
  created_by INT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  INDEX (equipment_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS toner_history (
  id INT AUTO_INCREMENT PRIMARY KEY,
  equipment_id INT NOT NULL,
  toner_model VARCHAR(120) NULL,
  quantity INT DEFAULT 1,
  action VARCHAR(80) DEFAULT 'troca',
  notes TEXT NULL,
  created_by INT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  INDEX (equipment_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
