<?php

namespace Database\Factories;

use App\Models\ProviderConnection;
use App\Models\ProviderCredential;
use App\Support\Providers\ProviderCredentialKind;
use App\Support\Providers\ProviderCredentialSource;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<ProviderCredential>
 */
class ProviderCredentialFactory extends Factory
{
    protected $model = ProviderCredential::class;

    public function definition(): array
    {
        return [
            'provider_connection_id' => ProviderConnection::factory()->dedicated(),
            'type' => 'client_secret',
            'credential_kind' => ProviderCredentialKind::ClientSecret->value,
            'source' => ProviderCredentialSource::DedicatedManual->value,
            'last_rotated_at' => now(),
            'expires_at' => now()->addYear(),
            'payload' => [
                'client_id' => fake()->uuid(),
                'client_secret' => fake()->sha1(),
            ],
        ];
    }

    public function standard(): static
    {
        return $this->state(fn (): array => [
            'provider_connection_id' => ProviderConnection::factory()->standard(),
        ]);
    }

    public function verifiedConnection(): static
    {
        return $this->standard();
    }

    public function legacyMigrated(): static
    {
        return $this->state(fn (): array => [
            'source' => ProviderCredentialSource::LegacyMigrated->value,
            'last_rotated_at' => null,
            'expires_at' => null,
        ]);
    }
}
