<?php

namespace Database\Factories;

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

/** @extends Factory<AnalyticsCache> */
class AnalyticsCacheFactory extends Factory
{
    protected $model = AnalyticsCache::class;

    public function definition(): array
    {
        $data = ['value' => fake()->numberBetween(1, 10000)];
        $dimensions = ['period' => 'today'];

        return [
            'cache_key' => 'analytics:'.Str::uuid(),
            'cache_data' => json_encode($data, JSON_THROW_ON_ERROR),
            'data_hash' => hash('sha256', json_encode($data, JSON_THROW_ON_ERROR)),
            'module' => 'executive',
            'metric' => 'total_users',
            'dimensions' => $dimensions,
            'dimensions_hash' => hash('sha256', json_encode($dimensions, JSON_THROW_ON_ERROR)),
            'version' => 1,
            'calculated_at' => now(),
            'expires_at' => now()->addMinutes(15),
            'created_at' => now(),
        ];
    }
}
