<?php declare(strict_types=1);

require_once __DIR__ . '/QrbRecipient.php';

// Holds an entry in the QR bill protocol.
final class QrbProtocolEntry
{
    private QrbRecipient $recipient;
    private bool            $pdfWritten  = false;
    private bool            $mailSent    = false;
    
    // Creates an instance for the given recipient.
    public function __construct(QrbRecipient $recipient)
    {
        $this->recipient = $recipient;
    }

    // Marks that the PDF file has been written.
    public function markPdfWritten(bool $pdfWritten)
    {
        $this->pdfWritten = $pdfWritten;
    }
    
    // Marks that mail has been sent (or not) according to the given flag.
    public function markMailSent(bool $mailSent)
    {
        $this->mailSent = $mailSent;
    }

    // Returns an array to be written to the protocol.    
    public function toArray() : array
    {
        return [  $this->recipient->getIndex(),
                  $this->recipient->getLastName(), 
                  $this->recipient->getFirstName(), 
                  $this->recipient->getMailAddress(), 
                  $this->pdfWritten ? "true" : "false",
                  $this->mailSent   ? "true" : "false"
               ];
    }
    
    public function __toString()
    {
        return  "\n\trecipient  = " . $this->recipient
              . "\n\tpdfWritten = " . ($this->pdfWritten ? "true" : "false")
              . "\n\tmailSent   = " . ($this->mailSent   ? "true" : "false");
    }
}

?>
