<?php

namespace ProudNerds\PostTypes;

use ProudNerds\WordPress\Register\PostType;
use ProudNerds\WordPress\Register\Taxonomy;

/**
 * This file provides an example for creating post types, feel free to rename or delete this file. All functions
 * displayed are optional and filled with either the default value or an example value to pass to the function. Consult
 * the PostType class comments for more information or the WordPress developer page.
 *
 * @see https://developer.wordpress.org/reference/functions/register_post_type/
 */
final class Example extends AbstractPostType {
    /**
     * Initializes the class. Calls the functions required to register the post type and optional taxonomies.
     */
    public function init() {
        $this->registerPostType();
        $this->registerTaxonomies();
    }

    /**
     * Registers the custom post type.
     */
    private function registerPostType() {
        PostType::factory('example')
            ->setLabels('Examples', 'Example')
            ->setDescription('A description of the post type')
            ->setPublic(false)
            ->setExcludeFromSearch(true)
            ->setPubliclyQueryable(false)
            ->setShowUI(false)
            ->setShowInNavMenus(false)
            ->setShowInMenu(false)
            ->setShowInAdminBar(false)
            ->setMenuPosition(25)
            ->setMenuIcon('dashicons-admin-post')
            ->setHasArchive(false)
            ->setSupports(['title', 'editor'])
            ->setCapabilityType('post')
            ->setCapabilities([
                'edit_post' => 'edit_example',
                'read_post' => 'read_example',
                'delete_post' => 'delete_example',
                'edit_posts' => 'edit_examples',
                'edit_others_posts' => 'edit_others_examples',
                'publish_posts' => 'publish_examples',
                'read_private_posts' => 'read_private_examples'
            ])
            ->setMapMetaCap(true)
            ->setHierarchical(false)
            ->setRegisterMetaBoxCB('postTypeMetaBoxCB')
            ->setTaxonomies(['example_categories', 'example_tags'])
            ->setRewrite(['slug' => 'example'])
            ->setQueryVar(true)
            ->setCanExport(true)
            ->setShowInRest(false)
            ->setRestBase('example')
            ->setRestControllerClass('WP_REST_Posts_Controller');
    }

    /**
     * Registers the custom taxonomy.
     */
    private function registerTaxonomies() {
        Taxonomy::factory('example-taxonomy', 'example')
            ->setLabels('Example Taxonomies', 'Example Taxonomy')
            ->setDescription('Example description of the taxonomy')
            ->setPublic(true)
            ->setShowUI(true)
            ->setShowInNavMenus(true)
            ->setShowInMenu(true)
            ->setShowTagcloud(true)
            ->setShowInRest(false)
            ->setShowInQuickEdit(false)
            ->setMetaBoxCB('taxonomyMetaBoxCB')
            ->setShowAdminColumn(false)
            ->setHierarchical(false)
            ->setUpdateCountCB('')
            ->setQueryVar('example-taxonomy')
            ->setRewrite(['slug' => 'example-taxonomy'])
            ->setCapabilities([
                'manage_terms' => 'manage_categories',
                'edit_terms'   => 'manage_categories',
                'delete_terms' => 'manage_categories',
                'assign_terms' => 'edit_posts'
            ])
            ->setSort(false);
            // ->forceHierarchicalDisplay();
    }

    /**
     * Callback function for PostType::factory()->setRegisterMetaBoxCB()
     */
    function postTypeMetaBoxCB() {
    }

    /**
     * Callback function for Taxonomy::factory()->setRegisterMetaBoxCB()
     */
    function taxonomyMetaBoxCB() {
    }
}