<?php

namespace Limb_Chatbot\Includes\Data_Objects;

/**
 * Notification log data object.
 *
 * Maps to the `lbaic_notification_log` table.
 *
 * @since 2.0.1
 */
class Notification_Log extends WPDB_Data_Object {

	/**
	 * Database table name.
	 */
	const TABLE_NAME = 'lbaic_notification_log';

	/**
	 * Attributes allowed for mass assignment / where filters.
	 *
	 * @var array<string>
	 */
	const FILLABLE = [
		'id',
		'chatbot_user_id',
		'type_key',
		'channel',
		'status',
		'sent_at',
		'fail_reason',
		'content_type',
		'content',
	];

	/**
	 * @json_excluded
	 * @var array|string[]
	 */
	public array $meta_properties = [ 'chatbot_user' ];

	/**
	 * Primary ID.
	 *
	 * @var int|null
	 */
	public ?int $id = null;

	/**
	 * Chatbot user ID associated with the notification.
	 *
	 * @var int
	 */
	public int $chatbot_user_id;

	/**
	 * Notification type key.
	 *
	 * @var string
	 */
	public string $type_key;

	/**
	 * Notification channel key.
	 *
	 * @var string
	 */
	public string $channel;

	/**
	 * Notification status (pending|sent|failed).
	 *
	 * @var string
	 */
	public string $status = 'pending';

	/**
	 * When the notification was sent (or null if pending).
	 *
	 * @var string|null
	 */
	public ?string $sent_at = null;

	/**
	 * Failure reason when status is failed.
	 *
	 * @var string|null
	 */
	public ?string $fail_reason = null;

	/**
	 * Content type (e.g., text/plain, text/html).
	 *
	 * @var string|null
	 */
	public ?string $content_type = null;

	/**
	 * Content payload.
	 *
	 * @var string|null
	 */
	public ?string $content = null;

	/**
	 * Included (non-column) related objects.
	 *
	 * @var array<string, mixed>
	 * @json_excluded
	 */
	public array $included = [];

	/**
	 * Get the chatbot user ID.
	 *
	 * @return int|null
	 * @since 2.0.1
	 */
	public function get_chatbot_user_id(): ?int {
		return $this->chatbot_user_id ?? null;
	}
}

