<?php

namespace GemBoards\entities;

use GemBoards\Classes\AbstractEntity;

class BoardVisit extends AbstractEntity {

	protected string $table       = 'gemboards_board_visits';
	protected string $object_type = 'board_visit';

	protected array $data = [
		'board_id'   => 0,
		'user_id'    => 0,
		'visited_at' => '',
	];

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

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

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

	public function set_board_id( int $value ) {
		$this->set_prop( 'board_id', $value );
	}

	public function set_user_id( $value ) {
		$this->set_prop( 'user_id', $value );
	}

	protected function prepare_for_db( string $context = 'create' ): array {
		if ( 'create' === $context ) {
			$now = current_time( 'mysql', 1 );
			$this->set_date_prop( 'visited_at', $now );
		}
		return parent::prepare_for_db( $context );
	}

}
