<?php

namespace App\OldDataMigrations;

class OrdersMigration extends BaseOldDataMigration
{
    public function priority(): int
    {
        return 9;
    }

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

        $results['orders'] = $this->migrateTableWithoutColumns('orders', ['marketplace_settings_snapshot', 'is_affiliate'], function ($row) {
            $row['cogs'] = $row['cogs'] ?? 0;

            $row['price_type'] = match ($row['price_type']) {
                'grosir' => 'wholesale',
                'harga_modal' => 'capital',
                default => $row['price_type'],
            };

            return $row;
        });

        $results['order_items'] = $this->migrateTable('order_items', function ($row) {
            $row['stock_quality'] = match ($row['stock_quality']) {
                'retail' => 'good',
                default => $row['stock_quality'],
            };

            return $row;
        });
        $results['activity_log'] = $this->migrateTable('activity_log');

        return $results;
    }
}
