<?php

namespace GemBoards\Entities;

use GemBoards\Classes\AbstractEntity;


class Role extends AbstractEntity {

	protected string $table       = 'gemboards_roles';
	protected string $object_type = 'role';

	protected array $data = [
		'user_id'     => 0,
		'object_id'   => '',
		'object_type' => 'project',
		'role'        => '',
	];

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

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

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

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

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

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

	public function set_role( string $value ) {
		$this->set_prop( 'role', $value );
	}

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

		return $data;
	}

}
