<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase, WordPress.Files.FileName.InvalidClassFileName
/**
 * WordPress-options-backed implementation of the Snooze settings reader.
 *
 * @package Autoship\Services\Snooze\Implementations
 * @since   2.13.0
 */

namespace Autoship\Services\Snooze\Implementations;

use Autoship\Services\Snooze\Interfaces\SnoozeSettingsInterface;

/**
 * Reads Snooze configuration from WordPress options.
 */
class SnoozeSettings implements SnoozeSettingsInterface {

	/**
	 * @inheritDoc
	 */
	public function is_enabled(): bool {
		$enabled = 'yes' === get_option( 'autoship_snooze_enabled', 'no' );

		return (bool) apply_filters( 'autoship_snooze_enabled', $enabled );
	}

	/**
	 * @inheritDoc
	 */
	public function get_action_label(): string {
		$label = get_option( 'autoship_snooze_action_label', 'Snooze' );

		if ( empty( $label ) ) {
			$label = 'Snooze';
		}

		return (string) apply_filters( 'autoship_snooze_action_label', $label );
	}

	/**
	 * @inheritDoc
	 */
	public function get_pause_behavior(): string {
		$behavior = get_option( 'autoship_snooze_pause_behavior', 'alongside' );

		if ( ! in_array( $behavior, array( 'alongside', 'instead' ), true ) ) {
			$behavior = 'alongside';
		}

		return (string) apply_filters( 'autoship_snooze_pause_behavior', $behavior );
	}

	/**
	 * @inheritDoc
	 */
	public function get_frequency_source(): string {
		$source = get_option( 'autoship_snooze_frequency_source', 'qmc' );

		if ( ! in_array( $source, array( 'qmc', 'plugin' ), true ) ) {
			$source = 'qmc';
		}

		return (string) apply_filters( 'autoship_snooze_frequency_source', $source );
	}

	/**
	 * @inheritDoc
	 */
	public function is_custom_date_allowed(): bool {
		$allowed = 'yes' === get_option( 'autoship_snooze_allow_custom_date', 'yes' );

		return (bool) apply_filters( 'autoship_snooze_allow_custom_date', $allowed );
	}

	/**
	 * @inheritDoc
	 */
	public function get_max_duration_days(): int {
		$max = get_option( 'autoship_snooze_max_duration_days', 180 );

		if ( '' === $max || null === $max ) {
			$max = 0;
		}

		$max = absint( $max );

		return (int) apply_filters( 'autoship_snooze_max_duration_days', $max );
	}
}
