<?php

namespace GemBoards\Entities;

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


class UserInvitation extends AbstractEntity {

	protected string $table       = 'gemboards_user_invitations';
	protected string $object_type = 'user_invitation';

	protected array $data = [
		'object_id'        => 0,
		'object_type'      => 'project',
		'email'            => '',
		'hash'             => '',
		'email_sent_count' => 0,
		'created_at'       => '',
		'expired_at'       => '',
	];

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

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

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

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

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

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

	public function get_date_expired( string $context = 'view' ): ?Datetime {
		return $this->get_expired_at( $context );
	}

	protected function get_expired_at( string $context = 'view' ): ?Datetime {
		return $this->get_prop( 'expired_at', $context );
	}

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

	public function set_email( string $value ): void {
		$this->set_prop( 'email', $value );
	}

	public function set_hash( string $value ): void {
		$this->set_prop( 'hash', $value );
	}

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

	public function set_expired_at( ?string $value ) {
		$this->set_date_prop( 'expired_at', $value );
	}

	protected function prepare_for_db( string $context = 'create' ): array {
		$data                        = parent::prepare_for_db( $context );
		$data['data']['object_type'] = $this->get_access_type();

		return $data;
	}

}
