<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class IntegratePalace_Properties_Register_Properties {

    public function register_palace_properties() {
        if ( post_type_exists( 'palace-properties' ) ) {
            return;
        }

        $labels = array(
            'name'               => _x( 'Palace Properties', 'post type general name', 'integrate-palace-properties' ),
            'singular_name'      => _x( 'Palace Property', 'post type singular name', 'integrate-palace-properties' ),
            'menu_name'          => _x( 'Palace Properties', 'admin menu', 'integrate-palace-properties' ),
            'name_admin_bar'     => _x( 'Palace Property', 'add new on admin bar', 'integrate-palace-properties' ),
            'add_new'            => _x( 'Add New', 'palace property', 'integrate-palace-properties' ),
            'add_new_item'       => __( 'Add New Palace Property', 'integrate-palace-properties' ),
            'new_item'           => __( 'New Palace Property', 'integrate-palace-properties' ),
            'edit_item'          => __( 'Edit Palace Property', 'integrate-palace-properties' ),
            'view_item'          => __( 'View Palace Property', 'integrate-palace-properties' ),
            'all_items'          => __( 'All Palace Properties', 'integrate-palace-properties' ),
            'search_items'       => __( 'Search Palace Properties', 'integrate-palace-properties' ),
            'parent_item_colon'  => __( 'Parent Palace Properties:', 'integrate-palace-properties' ),
            'not_found'          => __( 'No palace properties found.', 'integrate-palace-properties' ),
            'not_found_in_trash' => __( 'No palace properties found in Trash.', 'integrate-palace-properties' ),
        );

        $args = array(
            'labels'             => $labels,
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_rest'       => true,
            'query_var'          => true,
            'rewrite'            => array(
                'slug'       => get_option( 'integrate_palace_properties_slug', 'palace-property' ),
                'with_front' => false,
                'pages'      => true,
            ),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => array( 'title', 'thumbnail' ),
            'show_in_nav_menus'  => false,
            'show_in_menu'       => false,
        );

        register_post_type( 'palace-properties', $args );

        // Disable Gutenberg block editor for properties — use classic meta box interface
        add_filter( 'use_block_editor_for_post_type', function( $use, $post_type ) {
            if ( $post_type === 'palace-properties' ) {
                return false;
            }
            return $use;
        }, 10, 2 );

        // === Register Taxonomies ===

        // Property Type (Residential, Commercial, etc.)
        register_taxonomy( 'palace-property-type', 'palace-properties', array(
            'labels' => array(
                'name'          => __( 'Property Types', 'integrate-palace-properties' ),
                'singular_name' => __( 'Property Type', 'integrate-palace-properties' ),
                'search_items'  => __( 'Search Property Types', 'integrate-palace-properties' ),
                'all_items'     => __( 'All Property Types', 'integrate-palace-properties' ),
                'edit_item'     => __( 'Edit Property Type', 'integrate-palace-properties' ),
                'add_new_item'  => __( 'Add New Property Type', 'integrate-palace-properties' ),
            ),
            'hierarchical'      => true,
            'public'            => true,
            'show_in_rest'      => true,
            'show_admin_column' => true,
            'rewrite'           => array( 'slug' => 'property-type' ),
        ) );

        // Property Status (Active, Inactive)
        register_taxonomy( 'palace-property-status', 'palace-properties', array(
            'labels' => array(
                'name'          => __( 'Property Status', 'integrate-palace-properties' ),
                'singular_name' => __( 'Status', 'integrate-palace-properties' ),
                'search_items'  => __( 'Search Statuses', 'integrate-palace-properties' ),
                'all_items'     => __( 'All Statuses', 'integrate-palace-properties' ),
            ),
            'hierarchical'      => false,
            'public'            => true,
            'show_in_rest'      => true,
            'show_admin_column' => true,
            'rewrite'           => array( 'slug' => 'property-status' ),
        ) );

        // Region
        register_taxonomy( 'palace-property-region', 'palace-properties', array(
            'labels' => array(
                'name'          => __( 'Regions', 'integrate-palace-properties' ),
                'singular_name' => __( 'Region', 'integrate-palace-properties' ),
                'search_items'  => __( 'Search Regions', 'integrate-palace-properties' ),
                'all_items'     => __( 'All Regions', 'integrate-palace-properties' ),
            ),
            'hierarchical'      => true,
            'public'            => true,
            'show_in_rest'      => true,
            'show_admin_column' => true,
            'rewrite'           => array( 'slug' => 'property-region' ),
        ) );

        // Management Type
        register_taxonomy( 'palace-property-management', 'palace-properties', array(
            'labels' => array(
                'name'          => __( 'Management Types', 'integrate-palace-properties' ),
                'singular_name' => __( 'Management Type', 'integrate-palace-properties' ),
                'search_items'  => __( 'Search Management Types', 'integrate-palace-properties' ),
                'all_items'     => __( 'All Management Types', 'integrate-palace-properties' ),
            ),
            'hierarchical'      => false,
            'public'            => true,
            'show_in_rest'      => true,
            'show_admin_column' => true,
            'rewrite'           => array( 'slug' => 'property-management' ),
        ) );
    }
}
