<?php

namespace GemBoards\Entities;

use GemBoards\Classes\AbstractEntity;
use GemBoards\Utils\Helper;


class NotifiedUser extends AbstractEntity {

	protected string $table       = 'gemboards_notified_users';
	protected string $object_type = 'notified_user';

	protected array $data = [
		'to_user_id'      => 0,
		'notification_id' => 0,
		'is_read'         => false,
		'created_at'      => '',
	];

	public function get_to_user_id( string $context = 'view' ): int {
		return (int) $this->get_prop( 'to_user_id', $context );
	}

	public function get_notification_id( string $context = 'view' ) {
		return $this->get_prop( 'notification_id', $context );
	}

	protected function get_is_read( string $context = 'view' ): bool {
		return $this->get_prop( 'is_read', $context );
	}

	public function is_read( string $context = 'view' ) {
		return $this->get_is_read( $context );
	}

	public function get_date_created( string $context = 'view' ) {
		return $this->get_prop( 'created_at', $context );
	}

	public function set_to_user_id( int $value ): void {
		$this->set_prop( 'to_user_id', $value );
	}

	public function set_notification_id( int $value ): void {
		$this->set_prop( 'notification_id', $value );
	}

	public function set_is_read( $value ): void {
		$this->set_prop( 'is_read', Helper::string_to_bool( $value ) );
	}

	public function create() {
		parent::create();
		if ( empty( $this->wpdb->last_error ) ) {
			do_action( 'gemboards/notification/notified_user/created', $this );
		}
	}

}
