<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Index(columns: ['advert_id'], name: 'idx_advert_payment_advert')]
#[ORM\Index(columns: ['type'], name: 'idx_advert_payment_type')]
class AdvertPayment
{
    public const TYPE_SUCCESS = 'success';
    public const TYPE_REFUSED = 'refused';

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Advert::class, inversedBy: 'payments')]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Advert $advert;

    #[ORM\Column(length: 20)]
    private string $type;

    #[ORM\Column(type: 'decimal', precision: 10, scale: 2)]
    private string $amount;

    #[ORM\Column(length: 30, nullable: true)]
    private ?string $method = null;

    #[ORM\ManyToOne(targetEntity: \App\Entity\Echeancier::class)]
    #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
    private ?\App\Entity\Echeancier $echeancier = null;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    public function __construct(Advert $advert, string $type, string $amount)
    {
        $this->advert = $advert;
        $this->type = $type;
        $this->amount = $amount;
        $this->createdAt = new \DateTimeImmutable();
    }

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

    public function getAdvert(): Advert
    {
        return $this->advert;
    }

    public function getType(): string
    {
        return $this->type;
    }

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

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

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

        return $this;
    }

    public function getEcheancier(): ?\App\Entity\Echeancier
    {
        return $this->echeancier;
    }

    public function setEcheancier(?\App\Entity\Echeancier $echeancier): static
    {
        $this->echeancier = $echeancier;

        return $this;
    }

    public function getCreatedAt(): \DateTimeImmutable
    {
        return $this->createdAt;
    }
}
