<?php

class Zbr_Post_types
{
    public function __construct()
    {
        add_action('init', array($this, 'init'));
    }

    public function init()
    {
        $this->register_post_types();
    }

    public function register_post_types()
    {
        // News
        register_post_type(
            'zbr_news',
            array(
                'labels' => array(
                    'name' => __('ZBR Nieuwsberichten', 'zbr-api'),
                    'singular_name' => __('ZBR Nieuwsbericht', 'zbr-api'),
                ),
                'hierarchical' => false,
                'public' => true,
                'show_in_rest' => true,
                'show_in_admin_bar' => false,
                'rewrite' => ['slug' => 'news'],
                'supports' => [],
                'taxonomies' => ['post_tag'],
            )
        );

        // Agenda
        register_post_type(
            'zbr_agenda',
            [
                'labels' => [
                    'name' => __('ZBR Agendaitems', 'zbr-api'),
                    'singular_name' => __('ZBR Agenda item', 'zbr-api'),
                ],
                'hierarchical' => false,
                'public' => true,
                'show_in_rest' => true,
                'show_in_admin_bar' => false,
                'rewrite' => ['slug' => 'agenda'],
                'supports' => [],
                'taxonomies' => ['post_tag'],
            ]
        );

        // Zones
        register_post_type(
            'zbr_zone_team_member',  // The name of the posttype. Name should be in slug form (must not contain capital letters or spaces).
            [
                'public' => true,
                'hierarchical' => false,
                'labels' => [
                    'name' => __('ZBR Teammembers', 'zbr-api'),
                    'singular_name' => __('ZBR Teammember', 'zbr-api'),
                ],
                'rewrite' => [
                    'slug' => 'leden',    // This controls the base slug that will display before each term
                ]
            ]
        );

        register_post_type(
            'zbr_zone',
            [
                'labels' => [
                    'name' => __('ZBR Zones', 'zbr-api'),
                    'singular_name' => __('ZBR Zone', 'zbr-api'),
                ],
                'hierarchical' => false,
                'public' => true,
                'show_in_rest' => true,
                'show_in_admin_bar' => false,
                'rewrite' => ['slug' => 'zone'],
                'supports' => [],
                'taxonomies' => ['post_tag'],
            ]
        );

        register_rest_field('zbr_news', 'metadata', array(
            'get_callback' => function ($data) {
                return get_post_meta($data['id'], '', '');
            }
        ));
        register_rest_field('zbr_agenda', 'metadata', array(
            'get_callback' => function ($data) {
                return get_post_meta($data['id'], '', '');
            }
        ));
        register_rest_field('zbr_zone', 'metadata', array(
            'get_callback' => function ($data) {
                return get_post_meta($data['id'], '', '');
            }
        ));
        register_rest_field('zbr_zone_team_member', 'metadata', array(
            'get_callback' => function ($data) {
                return get_post_meta($data['id'], '', '');
            }
        ));
    }
}

new Zbr_Post_types();
