<?php

namespace Database\Factories;

use App\Models\Device;
use App\Models\SimHistory;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/** @extends Factory<SimHistory> */
class SimHistoryFactory extends Factory
{
    protected $model = SimHistory::class;

    public function definition(): array
    {
        $oldSim = fake()->numerify('####################');
        $newSim = fake()->numerify('####################');

        return [
            'uuid' => (string) Str::uuid(),
            'device_id' => Device::factory(),
            'user_id' => fn (array $attributes) => Device::query()->find($attributes['device_id'])?->user_id,
            'old_sim' => $oldSim,
            'new_sim' => $newSim,
            'old_sim_hash' => hash('sha256', $oldSim),
            'new_sim_hash' => hash('sha256', $newSim),
            'change_type' => 'sim_replaced',
            'change_reason' => 'Detected by device monitoring',
            'detected_at' => now(),
            'latitude' => fake()->latitude(8, 37),
            'longitude' => fake()->longitude(68, 97),
            'country' => 'India',
            'authorized' => false,
        ];
    }
}
