<?php
namespace SabaiApps\Directories\Component\Entity\FieldType;

use SabaiApps\Directories\Component\Entity;
use SabaiApps\Directories\Component\Field;

class IdFieldType extends Field\Type\AbstractType implements
	Field\Type\ISortable,
	Field\Type\IQueryable,
	Field\Type\IHumanReadable {

	use QueryableIdTrait;

	protected function _fieldTypeInfo() {
		return array(
			'label'     => __( 'ID', 'directories-pro' ),
			'creatable' => false,
			'icon'      => 'fas fa-hashtag',
		);
	}

	public function fieldSortableOptions( Field\IField $field ) {
		return array(
			array(),
			array(
				'args'  => array( 'desc' ),
				'label' => __( '%s (desc)', 'directories-pro' ),
			),
		);
	}

	public function fieldSortableSort( Field\Query $query, $fieldName, ?array $args = null ) {
		$query->sortById( isset( $args ) && $args[0] === 'desc' ? 'DESC' : 'ASC' );
	}

	public function fieldHumanReadableText( Field\IField $field, Entity\Type\IEntity $entity, $separator = null, $key = null ) {
		return $entity->getId();
	}
}
