<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Payment\Model;

use CpCreation\VitiCore\Behavior\HasPayment;
use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Cart\Model\PaymentMethod;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity]
#[ORM\Table(name: 'payment_payment')]
#[ORM\HasLifecycleCallbacks]
class Payment implements HasTimestamp, HasPayment
{
    use Timestamp;

    #[ORM\Id]
    #[ORM\Column(type: 'uuid')]
    #[ORM\GeneratedValue(strategy: 'NONE')]
    private UuidInterface $id;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $lastname = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $firstname = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $street = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $postalCode = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $city = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $email = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $phone = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $reference = null;

    #[ORM\Column(type: 'string')]
    #[Gedmo\Slug(fields: ['reference'])]
    private ?string $slug = null;

    #[ORM\Column(type: 'integer')]
    #[Assert\NotBlank]
    private ?int $amount = null;

    #[ORM\Column(type: 'datetime', nullable: true)]
    private ?\DateTime $payedAt = null;

    /**
     * @var array<mixed>
     */
    #[ORM\Column(type: 'json', nullable: true)]
    private array $response = [];

    #[ORM\ManyToOne(targetEntity: PaymentMethod::class)]
    #[ORM\JoinColumn(name: 'payment_method_id', referencedColumnName: 'id', nullable: true)]
    private ?PaymentMethod $paymentMethod = null;

    public function __construct()
    {
        $this->id = Uuid::uuid4();
        $this->response = [];
    }

    public function getId(): UuidInterface
    {
        return $this->id;
    }

    public function getLastname(): ?string
    {
        return $this->lastname;
    }

    public function setLastname(string $lastname): void
    {
        $this->lastname = $lastname;
    }

    public function getFirstname(): ?string
    {
        return $this->firstname;
    }

    public function setFirstname(string $firstname): void
    {
        $this->firstname = $firstname;
    }

    public function getStreet(): ?string
    {
        return $this->street;
    }

    public function setStreet(string $street): void
    {
        $this->street = $street;
    }

    public function getPostalCode(): ?string
    {
        return $this->postalCode;
    }

    public function setPostalCode(string $postalCode): void
    {
        $this->postalCode = $postalCode;
    }

    public function getCity(): ?string
    {
        return $this->city;
    }

    public function setCity(string $city): void
    {
        $this->city = $city;
    }

    public function getEmail(): ?string
    {
        return $this->email;
    }

    public function setEmail(string $email): void
    {
        $this->email = $email;
    }

    public function getPhone(): ?string
    {
        return $this->phone;
    }

    public function setPhone(string $phone): void
    {
        $this->phone = $phone;
    }

    public function getReference(): ?string
    {
        return $this->reference;
    }

    public function setReference(string $reference): void
    {
        $this->reference = $reference;
    }

    public function getSlug(): ?string
    {
        return $this->slug;
    }

    public function setSlug(string $slug): void
    {
        $this->slug = $slug;
    }

    public function getAmount(): ?int
    {
        return $this->amount;
    }

    public function setAmount(int $amount): void
    {
        $this->amount = $amount;
    }

    public function getPayedAt(): ?\DateTime
    {
        return $this->payedAt;
    }

    public function setPayedAt(?\DateTime $payedAt): void
    {
        $this->payedAt = $payedAt;
    }

    /**
     * @return array<mixed>
     */
    public function getResponse(): array
    {
        return $this->response;
    }

    /**
     * @param array<mixed> $response
     */
    public function setResponse(array $response): void
    {
        $this->response = $response;
    }

    public function getPaymentMethod(): ?PaymentMethod
    {
        return $this->paymentMethod;
    }

    public function setPaymentMethod(?PaymentMethod $paymentMethod): void
    {
        $this->paymentMethod = $paymentMethod;
    }

    public function getTotal(): ?int
    {
        return $this->getAmount();
    }

    public function getToken(): ?string
    {
        return $this->getSlug();
    }

    public function getCompany(): ?string
    {
        return null;
    }

    public function getCountry(): ?string
    {
        return 'FR';
    }

    public function getQuantity(): int
    {
        return 1;
    }
}
