__( 'Short-term (Nightly)', 'wp-bnb' ), self::MID_TERM => __( 'Mid-term (Weekly)', 'wp-bnb' ), self::LONG_TERM => __( 'Long-term (Monthly)', 'wp-bnb' ), }; } /** * Get the unit label for this tier. * * @return string */ public function unit(): string { return match ( $this ) { self::SHORT_TERM => __( 'per night', 'wp-bnb' ), self::MID_TERM => __( 'per week', 'wp-bnb' ), self::LONG_TERM => __( 'per month', 'wp-bnb' ), }; } /** * Get the unit label for this tier (singular). * * @return string */ public function unitSingular(): string { return match ( $this ) { self::SHORT_TERM => __( 'night', 'wp-bnb' ), self::MID_TERM => __( 'week', 'wp-bnb' ), self::LONG_TERM => __( 'month', 'wp-bnb' ), }; } /** * Get the unit label for this tier (plural). * * @return string */ public function unitPlural(): string { return match ( $this ) { self::SHORT_TERM => __( 'nights', 'wp-bnb' ), self::MID_TERM => __( 'weeks', 'wp-bnb' ), self::LONG_TERM => __( 'months', 'wp-bnb' ), }; } /** * Get the default minimum nights for this tier. * * @return int */ public function defaultMinNights(): int { return match ( $this ) { self::SHORT_TERM => 1, self::MID_TERM => 7, self::LONG_TERM => 28, }; } /** * Get the default maximum nights for this tier. * * @return int|null Null means unlimited. */ public function defaultMaxNights(): ?int { return match ( $this ) { self::SHORT_TERM => 6, self::MID_TERM => 27, self::LONG_TERM => null, }; } /** * Determine the pricing tier based on number of nights. * * @param int $nights Number of nights. * @param int|null $short_term_max Maximum nights for short-term. Default 6. * @param int|null $mid_term_max Maximum nights for mid-term. Default 27. * @return self */ public static function fromNights( int $nights, ?int $short_term_max = null, ?int $mid_term_max = null ): self { $short_term_max = $short_term_max ?? (int) get_option( 'wp_bnb_short_term_max_nights', 6 ); $mid_term_max = $mid_term_max ?? (int) get_option( 'wp_bnb_mid_term_max_nights', 27 ); if ( $nights <= $short_term_max ) { return self::SHORT_TERM; } if ( $nights <= $mid_term_max ) { return self::MID_TERM; } return self::LONG_TERM; } /** * Get all tiers. * * @return array */ public static function all(): array { return self::cases(); } /** * Get tier options for select fields. * * @return array */ public static function options(): array { $options = array(); foreach ( self::cases() as $tier ) { $options[ $tier->value ] = $tier->label(); } return $options; } }