File: /home/xedaptot/ai.naniguide.com/database/factories/AdPlatformFactory.php
<?php
namespace Database\Factories;
use App\Model\AdPlatform;
use App\Model\Customer;
use Illuminate\Database\Eloquent\Factories\Factory;
class AdPlatformFactory extends Factory
{
protected $model = AdPlatform::class;
public function definition(): array
{
$platform = $this->faker->randomElement(AdPlatform::PLATFORMS);
return [
'uid' => uniqid(),
'customer_id' => Customer::factory(),
'platform' => $platform,
'name' => AdPlatform::PLATFORM_LABELS[$platform],
'access_token' => 'mock_access_' . $this->faker->sha256(),
'refresh_token' => 'mock_refresh_' . $this->faker->sha256(),
'token_expires_at' => now()->addDays(60),
'platform_user_id' => (string) $this->faker->randomNumber(8),
'platform_user_name' => $this->faker->company(),
'scopes' => ['ads_management', 'ads_read'],
'status' => AdPlatform::STATUS_ACTIVE,
'health_status' => AdPlatform::HEALTH_HEALTHY,
'last_health_check_at' => now()->subMinutes(5),
];
}
public function meta(): static
{
return $this->state(fn () => ['platform' => AdPlatform::PLATFORM_META]);
}
public function google(): static
{
return $this->state(fn () => ['platform' => AdPlatform::PLATFORM_GOOGLE]);
}
public function tiktok(): static
{
return $this->state(fn () => ['platform' => AdPlatform::PLATFORM_TIKTOK]);
}
public function linkedin(): static
{
return $this->state(fn () => ['platform' => AdPlatform::PLATFORM_LINKEDIN]);
}
public function expired(): static
{
return $this->state(fn () => [
'status' => AdPlatform::STATUS_EXPIRED,
'health_status' => AdPlatform::HEALTH_ERROR,
'token_expires_at' => now()->subDays(1),
]);
}
public function system(): static
{
return $this->state(fn () => [
'customer_id' => null,
'admin_id' => 1,
]);
}
public function forCustomer(Customer $customer): static
{
return $this->state(fn () => ['customer_id' => $customer->id]);
}
}