<?php

declare(strict_types=1);

/*
 * 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\Cart\Model;

use CpCreation\VitiCore\Behavior\HasDisable;
use CpCreation\VitiCore\Behavior\HasImage;
use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\HasTranslatable;
use CpCreation\VitiCore\Behavior\Impl\Disable;
use CpCreation\VitiCore\Behavior\Impl\Image;
use CpCreation\VitiCore\Behavior\Impl\SoftDeletable;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Behavior\Impl\Translatable;
use CpCreation\VitiCore\Behavior\IsSoftDeletable;
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(repositoryClass: 'CpCreation\VitiCore\Cart\Repository\PaymentMethodRepository')]
#[ORM\Table(name: 'cart_payment_method')]
#[ORM\HasLifecycleCallbacks]
class PaymentMethod implements HasDisable, HasImage, HasTimestamp, HasTranslatable, IsSoftDeletable
{
    use Disable;
    use Image;
    use SoftDeletable;
    use Timestamp;
    use Translatable;

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

    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\NotBlank(groups: ['step1'])]
    private ?string $method = null;

    #[ORM\Column(type: 'boolean')]
    private bool $paymentOnline = false;

    #[ORM\Column(type: 'integer', options: ['default' => 0])]
    #[Gedmo\SortablePosition]
    private int $position = 0;

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

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

    public function getMethod(): ?string
    {
        return $this->method;
    }

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

    public function isPaymentOnline(): bool
    {
        return $this->paymentOnline;
    }

    public function setPaymentOnline(bool $paymentOnline): void
    {
        $this->paymentOnline = $paymentOnline;
    }

    public function isOfflinePayment(): bool
    {
        return !$this->paymentOnline;
    }

    public function setOfflinePayment(bool $offlinePayment): void
    {
        $this->paymentOnline = !$offlinePayment;
    }

    public function isCheckoutOfflineMethod(): bool
    {
        return !$this->paymentOnline;
    }

    public function isCheckoutOnlineMethod(): bool
    {
        return $this->paymentOnline;
    }

    public function getPosition(): int
    {
        return $this->position;
    }

    public function setPosition(int $position): void
    {
        $this->position = $position;
    }
}
