<?php

namespace App\Factory;

use App\DataFixtures\FakeValues;
use App\Entity\Partner;
use App\Enum\PartnerType;
use App\Repository\PartnerRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;

/**
 * @extends ModelFactory<Partner>
 *
 * @method        Partner|Proxy                     create(array|callable $attributes = [])
 * @method static Partner|Proxy                     createOne(array $attributes = [])
 * @method static Partner|Proxy                     find(object|array|mixed $criteria)
 * @method static Partner|Proxy                     findOrCreate(array $attributes)
 * @method static Partner|Proxy                     first(string $sortedField = 'id')
 * @method static Partner|Proxy                     last(string $sortedField = 'id')
 * @method static Partner|Proxy                     random(array $attributes = [])
 * @method static Partner|Proxy                     randomOrCreate(array $attributes = [])
 * @method static PartnerRepository|RepositoryProxy repository()
 * @method static Partner[]|Proxy[]                 all()
 * @method static Partner[]|Proxy[]                 createMany(int $number, array|callable $attributes = [])
 * @method static Partner[]|Proxy[]                 createSequence(iterable|callable $sequence)
 * @method static Partner[]|Proxy[]                 findBy(array $attributes)
 * @method static Partner[]|Proxy[]                 randomRange(int $min, int $max, array $attributes = [])
 * @method static Partner[]|Proxy[]                 randomSet(int $number, array $attributes = [])
 */
final class PartnerFactory extends ModelFactory
{
    private static $nameIndex = 0;

    /**
     * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
     *
     * @todo inject services if required
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
     *
     * @todo add your default values here
     */
    protected function getDefaults(): array
    {
        $name = FakeValues::COMPANY_NAMES[self::$nameIndex % count(FakeValues::COMPANY_NAMES)];
        $legalForm = self::faker()->randomElement(FakeValues::COMPANY_LEGAL_FORMS);
        self::$nameIndex++;
        return [
            'name' => $name . " " . $legalForm,
            'nameAddition' => self::faker()->text(20),
            'type' => self::faker()->randomElement(PartnerType::cases()),
            'description' => self::faker()->text(),
            'street' => self::faker()->randomElement(FakeValues::STREETS),
            'addressAddition' => self::faker()->randomElement(FakeValues::STREETS),
            'phone' => self::faker()->phoneNumber(),
            'language' => self::faker()->languageCode(),
            'currency' => self::faker()->currencyCode(),
            'paymentCondition' => self::faker()->randomElement(['30INV', '60BL', 'PP', 'CAD', 'SOFORT', '14INV', '5INV', '30INV14D2%', '']),
            'deliveryCondition' => self::faker()->randomElement(['FCA', 'FOB', 'DDP', 'DAP', '']),
            'businessGroup' => self::faker()->randomElement(['DE-DE', 'DRITT-DE', 'EU-DE', 'DRITT-DRITT', 'TRANSIT-DE', 'EU-DE-EU', '']),
            'vatBusinessGroup' => self::faker()->randomElement(['DE-DE', 'DRITT-DE', 'EU-DE', 'DRITT-DRITT', 'TRANSIT-DE', 'EU-DE-EU', '']),
            'creditLimit' => self::faker()->numberBetween(1000,1000000),
            'routePoint' => self::faker()->randomElement([
                'AT - SALZBURG', 'DE - TREBSEN/ MULDE', 'DE - GELSENKIRCHEN', 'CZ - PRAGUE', 'CH - BURGDORF', 'SI - PODNART', 'GB - ECCLES',
                'SK - HUMENNÉ', 'IN - NHAVA SHEVA', 'CN - SHANGHAI', 'JP - NAGOYA', 'CO - FLORIDABLANCA', 'ES - ZARAGOZA', 'FR - HARNES',
                'DE - HAMBURG', 'HU - NYÍREGYHÁZA', 'RO - TIMISOARA', 'SE - ROSERSBERG', 'TW - TAIPEY CITY', ''
            ]),
            'streetNo' => self::faker()->numberBetween(1,1000),
            'zip' => self::faker()->numberBetween(1000,10000),
            'city' => self::faker()->randomElement(FakeValues::CITIES),
            'country' => self::faker()->randomElement(FakeValues::COUNTRIES),
            'website' => 'https://spawntree.de/',
            'createdBy' => UserFactory::random()
        ];
    }

    /**
     * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
     */
    protected function initialize(): self
    {
        return $this
            // ->afterInstantiate(function(Partner $partner): void {})
        ;
    }

    protected static function getClass(): string
    {
        return Partner::class;
    }
}
