<?php

namespace App\Models;

class EmailLogModel extends TenantModel
{
    protected $table         = 'email_log';
    protected $primaryKey    = 'id';
    protected $returnType    = 'object';
    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = '';

    protected $allowedFields = [
        'guest_id',
        'to_email',
        'subject',
        'status',
        'error',
    ];

    public function record(?int $guestId, string $toEmail, string $subject, bool $success, ?string $error): void
    {
        $this->insert([
            'guest_id' => $guestId,
            'to_email' => $toEmail,
            'subject'  => $subject,
            'status'   => $success ? 'sent' : 'failed',
            'error'    => $error,
        ]);
    }
}
