<?php

namespace Database\Factories;

use App\Models\Transaction;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Transaction>
 */
class TransactionFactory extends Factory
{
    /**
     * Configure the model factory.
     *
     * @return $this
     */
    public function configure()
    {
        return $this->afterCreating(function (Transaction $transaction) {
            if ($transaction->type=='Payment'){
                $transaction->fromWallet->reserveMoneyActivity($transaction->amount, $transaction->milestone?->name);
                $transaction->toWallet->addUpcomingMoneyActivity($transaction->amount, $transaction->milestone?->name);
            }else{
                $transaction->fromWallet->releaseMoneyActivity($transaction->amount, $transaction->milestone?->name);
            }
        });
    }
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    {
        return [
            'amount'=> $this->faker->numberBetween(10,10000),
            'type'=>$this->faker->randomElement(['Payment','Payouts','Muhandisin Profit']),
            'milestone_id'=>$this->faker->numberBetween(1,50),
            'from'=>$this->faker->numberBetween(1,50),
            'status'=> $this->faker->randomElement(['paid','reserved','refunded']),
            'to'=>$this->faker->numberBetween(1,50),
        ];
    }
}
