<?php

namespace App\Support;

use App\Models\SupplierPayment;
use App\Models\SupplierPaymentAllocation;
use Illuminate\Support\Facades\DB;

class ClearSupplierPayments
{
    /**
     * Remove all supplier payments and bill allocations.
     * Purchase bills, suppliers, products, and stock are kept.
     *
     * @return array{allocations: int, payments: int}
     */
    public static function run(): array
    {
        return DB::transaction(function (): array {
            $allocationCount = SupplierPaymentAllocation::query()->count();
            $paymentCount = SupplierPayment::query()->count();

            SupplierPaymentAllocation::query()->delete();
            SupplierPayment::query()->delete();

            return [
                'allocations' => $allocationCount,
                'payments' => $paymentCount,
            ];
        });
    }
}
