<?php
/**
 * Reason Codes — structured return reasons available in the wizard's Step 2.
 *
 * @package WPNest_Returns_For_WooCommerce
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class WPNest_RFW_Reason_Codes {

    const CODE_OTHER = 'other';

    /**
     * Returns ordered map of reason_code => translated label.
     * Pro can extend / replace via the `wpnest_rfw_reason_codes` filter.
     *
     * @return array<string,string>
     */
    public static function get_all() {
        $codes = array(
            'too_small'            => __( 'Item too small', 'wpnest-returns-for-woocommerce' ),
            'too_large'            => __( 'Item too large', 'wpnest-returns-for-woocommerce' ),
            'quality_mismatch'     => __( 'Quality not as expected', 'wpnest-returns-for-woocommerce' ),
            'description_mismatch' => __( 'Item does not match the description', 'wpnest-returns-for-woocommerce' ),
            'damaged'              => __( 'Item damaged or defective', 'wpnest-returns-for-woocommerce' ),
            'wrong_item'           => __( 'Wrong item received', 'wpnest-returns-for-woocommerce' ),
            'dont_like'            => __( 'I do not like it / changed my mind', 'wpnest-returns-for-woocommerce' ),
            self::CODE_OTHER       => __( 'Other (please specify)', 'wpnest-returns-for-woocommerce' ),
        );

        $codes = apply_filters( 'wpnest_rfw_reason_codes', $codes );
        return is_array( $codes ) ? $codes : array();
    }

    /**
     * Whether the given code is a valid known reason.
     *
     * @param string $code
     * @return bool
     */
    public static function is_valid( $code ) {
        return array_key_exists( (string) $code, self::get_all() );
    }

    /**
     * Translate code to display label. Falls back to the raw code if unknown.
     *
     * @param string $code
     * @return string
     */
    public static function get_label( $code ) {
        $all = self::get_all();
        return isset( $all[ $code ] ) ? $all[ $code ] : (string) $code;
    }

    /**
     * Whether free-text comment is required for the given reason code.
     * Only `other` is mandatory by default; Pro may add more.
     *
     * @param string $code
     * @return bool
     */
    public static function requires_text( $code ) {
        return apply_filters( 'wpnest_rfw_reason_requires_text', self::CODE_OTHER === $code, $code );
    }
}
