<?php
namespace App\DataFixtures\ObjectMother;
use App\Entity\City;
use App\Entity\Customer;
use App\Entity\Embeddables\IdentityDocumentEmbeddable;
use Faker\Factory;
final class CustomerMother
{
public static function create(
?string $email = null,
City $city
): Customer {
$faker = Factory::create('es_ES');
$customer = new Customer();
$customer->setEmail($email ?? $faker->email());
$customer->setPassword('customer');
$customer->setName($faker->firstName());
$customer->setSurname(sprintf('%s %s', $faker->lastName(), $faker->lastName()));
$customer->setAvatar(sprintf('https://randomuser.me/api/portraits/men/%d.jpg', rand(1,100)));
$customer->setBirthday($faker->dateTimeBetween('-50 year', '-18 year'));
$customer->getDocument()->setType(rand(1, 2));
$customer->getDocument()->setNumber($faker->vat());
switch ($customer->getDocument()->getType()) {
case IdentityDocumentEmbeddable::TYPE_DNI:
$customer->getDocument()->setDateValid($faker->dateTimeBetween('1 year', '5 year'));
break;
case IdentityDocumentEmbeddable::TYPE_NIE:
$customer->getDocument()->setNumberSupport($faker->vat());
break;
}
$customer->setAddressType(Customer::ADDRESS_TYPE_OTHER);
$customer->getAddress()->setRegion($city->getRegion()->getName());
$customer->getAddress()->setCity($city->getName());
$customer->getAddress()->setStreet($faker->streetAddress());
$customer->getAddress()->setPostal($faker->postcode());
$customer->setPhone($faker->phoneNumber());
$customer->setStatus(Customer::STATUS_PUBLISHED);
$customer->setCdate($faker->dateTimeBetween('-1 year', '-1 month'));
return $customer;
}
}