<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Enums\RiskLevel;
use App\Enums\VerificationStatus;
use App\Models\SellerProfile;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends Factory<SellerProfile>
 */
class SellerProfileFactory extends Factory
{
    protected $model = SellerProfile::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        $name = fake()->company();

        return [
            'user_id' => User::factory(),
            'handle' => Str::slug($name).'-'.Str::lower(Str::random(5)),
            'display_name' => $name,
            'about' => fake()->sentence(12),
            'payout_currency' => 'USD',
            'identity_status' => VerificationStatus::Unverified,
            'payment_status' => VerificationStatus::Unverified,
            'risk_level' => RiskLevel::Low,
            'onboarded_at' => now(),

            /*
             * Nullable columns set explicitly, for the same reason as in
             * UserFactory: a created model must expose the same attributes as a
             * retrieved one or strict mode fails on unrelated reads.
             */
            'logo_path' => null,
            'support_email' => null,
            'listing_suspended_at' => null,
            'listing_suspension_reason' => null,
            'deleted_at' => null,
        ];
    }

    public function identityVerified(): static
    {
        return $this->state(fn (): array => ['identity_status' => VerificationStatus::Verified]);
    }

    public function paymentVerified(): static
    {
        return $this->state(fn (): array => ['payment_status' => VerificationStatus::Verified]);
    }

    /** A seller with enough verified history to reach the Pro tier. */
    public function pro(): static
    {
        return $this->state(fn (): array => [
            'identity_status' => VerificationStatus::Verified,
            'completed_sales_count' => 15,
        ]);
    }

    /** A seller with enough verified history to reach the Enterprise tier. */
    public function enterprise(): static
    {
        return $this->state(fn (): array => [
            'identity_status' => VerificationStatus::Verified,
            'completed_sales_count' => 75,
        ]);
    }

    public function listingSuspended(): static
    {
        return $this->state(fn (): array => [
            'listing_suspended_at' => now(),
            'listing_suspension_reason' => 'Testing suspension.',
        ]);
    }

    public function blocked(): static
    {
        return $this->state(fn (): array => ['risk_level' => RiskLevel::Blocked]);
    }
}
