<?php
/**
 * @package Hafenstudios\Kurato
 */

namespace Hafenstudios\Kurato\Campaign;

defined( 'ABSPATH' ) || exit;

/**
 * CPT `hs_mail` (K4-Konzept Abschnitt 2): der INHALT einer Kampagnen-Mail.
 *
 * Betreff = Post-Title, Inhalt = post_content (Gutenberg-Blocks). Der
 * Block-Editor liefert Revisionen und Autosave gratis (BAUPLAN 25). Der
 * Versandzustand liegt getrennt in `hs_campaigns` (CampaignRepository), nicht
 * am Post.
 *
 * Der Post-Type ist NICHT oeffentlich (kein Frontend, keine Query-Var, keine
 * Rewrite-Regel); `show_in_rest` ist aber true, weil der Block-Editor die
 * REST-API braucht. Die Zugriffsrechte haengen an der Sende-Capability
 * `hs_send_mails` (K2).
 */
final class MailPostType {

	public const POST_TYPE = 'hs_mail';

	/**
	 * Registriert den Post-Type (Aufruf im init-Hook).
	 *
	 * @return void
	 */
	public function register(): void {
		register_post_type(
			self::POST_TYPE,
			array(
				'labels'          => array(
					'name'          => __( 'Newsletter-Mails', 'kurato' ),
					'singular_name' => __( 'Newsletter-Mail', 'kurato' ),
					'add_new_item'  => __( 'Neue Newsletter-Mail', 'kurato' ),
					'edit_item'     => __( 'Newsletter-Mail bearbeiten', 'kurato' ),
					'new_item'      => __( 'Neue Newsletter-Mail', 'kurato' ),
					'view_item'     => __( 'Newsletter-Mail ansehen', 'kurato' ),
					'not_found'     => __( 'Keine Newsletter-Mails gefunden.', 'kurato' ),
				),
				'public'          => false,
				'show_ui'         => true,
				'show_in_menu'    => false,
				'show_in_rest'    => true,
				'supports'        => array( 'title', 'editor', 'revisions', 'custom-fields', 'autosave' ),
				'capability_type' => 'post',
				'capabilities'    => array(
					'edit_post'           => 'hs_send_mails',
					'read_post'           => 'hs_send_mails',
					'delete_post'         => 'hs_send_mails',
					'edit_posts'          => 'hs_send_mails',
					'edit_others_posts'   => 'hs_send_mails',
					'publish_posts'       => 'hs_send_mails',
					'read_private_posts'  => 'hs_send_mails',
					'delete_posts'        => 'hs_send_mails',
					'delete_others_posts' => 'hs_send_mails',
				),
				'map_meta_cap'    => false,
				'rewrite'         => false,
				'query_var'       => false,
				'has_archive'     => false,
			)
		);
	}
}
