<?php

namespace GemBoards\entities;

use GemBoards\Classes\AbstractEntity;

class CardAssignee extends AbstractEntity {

	protected string $table       = 'gemboards_card_assignees';
	protected string $object_type = 'assignee';

	protected array $data = [
		'card_id'    => 0,
		'user_id'    => 0,
		'updated_at' => '',
	];

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

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

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

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

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

	public function create() {
		parent::create();
		if ( $this->get_id() ) {
			do_action( 'gemboards/card/user_assigned', $this->get_card_id(), $this->get_user_id(), $this->get_id() );
		}
	}

	public function delete( bool $force_delete = false ): bool {
		if ( parent::delete( $force_delete ) ) {
			do_action( 'gemboards/card/user_removed', $this->get_card_id(), $this->get_user_id(), $this->get_id() );
			return true;
		}

		return false;
	}
}
