<?php
/**
 * Vehicle Model taxonomy (hierarchical — parent is make).
 *
 * @package ThemeREX\AutoDealer
 */

declare(strict_types=1);

namespace ThemeREX\AutoDealer\Taxonomies;

use ThemeREX\AutoDealer\PostTypes\VehiclePostType;

class ModelTaxonomy {

	public const TAXONOMY = 'trx_ad_model';

	/**
	 * Register the taxonomy.
	 *
	 * @return void
	 */
	public function register(): void {
		$labels = array(
			'name'                  => _x( 'Models', 'Taxonomy general name', 'trx-auto-dealer' ),
			'singular_name'         => _x( 'Model', 'Taxonomy singular name', 'trx-auto-dealer' ),
			'search_items'          => __( 'Search Models', 'trx-auto-dealer' ),
			'all_items'             => __( 'All Models', 'trx-auto-dealer' ),
			'parent_item'           => __( 'Parent Make', 'trx-auto-dealer' ),
			'parent_item_colon'     => __( 'Parent Make:', 'trx-auto-dealer' ),
			'edit_item'             => __( 'Edit Model', 'trx-auto-dealer' ),
			'update_item'           => __( 'Update Model', 'trx-auto-dealer' ),
			'add_new_item'          => __( 'Add New Model', 'trx-auto-dealer' ),
			'new_item_name'         => __( 'New Model Name', 'trx-auto-dealer' ),
			'menu_name'             => __( 'Models', 'trx-auto-dealer' ),
			'not_found'             => __( 'No models found.', 'trx-auto-dealer' ),
			'no_terms'              => __( 'No models', 'trx-auto-dealer' ),
			'items_list_navigation' => __( 'Models list navigation', 'trx-auto-dealer' ),
			'items_list'            => __( 'Models list', 'trx-auto-dealer' ),
			'back_to_items'         => __( '&larr; Back to Models', 'trx-auto-dealer' ),
		);

		$args = array(
			'labels'            => $labels,
			// Flat — Model→Make linkage is via term meta (`_trx_ad_model_make`)
			// because WP's same-taxonomy `parent` cannot point at terms in a
			// different taxonomy. See `Taxonomies\ModelMakeLink` for the
			// admin UI + storage.
			'hierarchical'      => false,
			'public'            => true,
			'show_ui'           => true,
			// false: list-table Model column already renders this with fallback.
			'show_admin_column' => false,
			'show_in_nav_menus' => true,
			'show_tagcloud'     => false,
			'show_in_rest'      => false,
			'rewrite'           => array(
				'slug'       => 'model',
				'with_front' => false,
			),
		);

		register_taxonomy( self::TAXONOMY, VehiclePostType::POST_TYPE, $args );
	}

	/**
	 * Return the default terms for this taxonomy.
	 *
	 * Models are added per-make; no defaults shipped.
	 *
	 * @return array<string, mixed>
	 */
	public function getDefaultTerms(): array {
		return array();
	}

	/**
	 * Insert default terms if the taxonomy is empty.
	 *
	 * No-op — models are added per make.
	 *
	 * @return void
	 */
	public function insertDefaultTerms(): void {
		// Models are added per make; nothing to seed.
	}
}
