<?php

namespace App\OldDataMigrations;

class InventoryMigration extends BaseOldDataMigration
{
    public function priority(): int
    {
        return 12;
    }

    public function migrate(): array
    {
        $results = [];

        $results['retail_stock_histories'] = $this->migrateTable('retail_stock_histories');
        $results['stok_opnames'] = $this->migrateTable('stok_opnames');
        $results['stok_opname_items'] = $this->migrateTable('stok_opname_items');
        $results['restocks'] = $this->migrateTableWithoutColumns('restocks', ['subtotal']);
        $results['restock_items'] = $this->migrateTable('restock_items');
        $results['stock_mutations'] = $this->migrateTable('stock_mutations', function ($row) {
            $fields = ['quantity', 'stock_before', 'stock_after'];
            foreach ($fields as $field) {
                if (isset($row[$field]) && is_string($row[$field])) {
                    $row[$field] = (int) round($row[$field]);
                }
            }

            return $row;
        });

        return $results;
    }
}
