<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (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\Cart\Model;

use CpCreation\VitiCore\Behavior\HasDisable;
use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\Impl\Disable;
use CpCreation\VitiCore\Behavior\Impl\SoftDeletable;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Behavior\IsSoftDeletable;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity(repositoryClass: 'CpCreation\VitiCore\Cart\Repository\CartCheckoutRepository')]
#[ORM\Table(name: 'cart_cart_checkout')]
#[ORM\HasLifecycleCallbacks]
class CartCheckout implements HasTimestamp, HasDisable, IsSoftDeletable
{
    use Disable;
    use SoftDeletable;
    use Timestamp;

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

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

    #[ORM\Column(type: 'datetime_immutable', nullable: true)]
    private ?\DateTimeImmutable $initiatedAt = null;

    #[ORM\Column(type: 'datetime_immutable', nullable: true)]
    private ?\DateTimeImmutable $orderedAt = null;

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

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

    #[ORM\Column(type: 'json', nullable: true)]
    private ?array $response = null;

    #[ORM\Column(type: 'json', nullable: true)]
    private ?array $marketingAttribution = null;

    #[ORM\OneToOne(targetEntity: Cart::class, inversedBy: 'cartCheckout')]
    #[ORM\JoinColumn(name: 'cart_cart_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
    private ?Cart $cart = null;

    public function __construct()
    {
        $this->id = Uuid::uuid4();
        $this->disabled = false;
    }

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

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

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

    public function getInitiatedAt(): ?\DateTimeImmutable
    {
        return $this->initiatedAt;
    }

    public function setInitiatedAt(?\DateTimeImmutable $initiatedAt): void
    {
        $this->initiatedAt = $initiatedAt;
    }

    public function isPaymentInitiated(): bool
    {
        return null !== $this->initiatedAt;
    }

    public function getOrderedAt(): ?\DateTimeImmutable
    {
        return $this->orderedAt;
    }

    public function setOrderedAt(?\DateTimeImmutable $orderedAt): void
    {
        $this->orderedAt = $orderedAt;
    }

    public function getPayedToken(): ?string
    {
        return $this->payedToken;
    }

    public function setPayedToken(?string $payedToken): void
    {
        $this->payedToken = $payedToken;
    }

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

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

    public function getResponse(): ?array
    {
        return $this->response;
    }

    public function setResponse(?array $response): void
    {
        $this->response = $response;
    }

    /**
     * @return array<string, mixed>|null
     */
    public function getMarketingAttribution(): ?array
    {
        return $this->marketingAttribution;
    }

    /**
     * @param array<string, mixed>|null $marketingAttribution
     */
    public function setMarketingAttribution(?array $marketingAttribution): void
    {
        $this->marketingAttribution = $marketingAttribution;
    }

    public function getCart(): ?Cart
    {
        return $this->cart;
    }

    public function setCart(?Cart $cart): void
    {
        $this->cart = $cart;
    }
}
