<?php
/**
 * Schedulable operation types.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Domain\Operation;

/**
 * String constants for OperationType values.
 */
class OperationType {

	public const SET_FIELD              = 'set_field';
	public const UNSET_FIELD            = 'unset_field';
	public const ADD_LIST_ITEM          = 'add_list_item';
	public const REMOVE_LIST_ITEM       = 'remove_list_item';
	public const REPLACE_LIST           = 'replace_list';
	public const ADD_TAXONOMY_TERM      = 'add_taxonomy_term';
	public const REMOVE_TAXONOMY_TERM   = 'remove_taxonomy_term';
	public const REPLACE_TAXONOMY_TERMS = 'replace_taxonomy_terms';
	public const CREATE_TAXONOMY_TERM   = 'create_taxonomy_term';
	public const SET_MEDIA              = 'set_media';
	public const PROVIDER_DEFINED       = 'provider_defined';
	public const CAPTURE_SNAPSHOT       = 'capture_snapshot';
	public const SYNCHRONIZE_PARENT     = 'synchronize_parent';
	public const CLEAR_CACHE            = 'clear_cache';
	public static function writesField( string $type ): bool {
		return in_array(
			$type,
			array(
				self::SET_FIELD,
				self::UNSET_FIELD,
				self::ADD_LIST_ITEM,
				self::REMOVE_LIST_ITEM,
				self::REPLACE_LIST,
				self::ADD_TAXONOMY_TERM,
				self::REMOVE_TAXONOMY_TERM,
				self::REPLACE_TAXONOMY_TERMS,
				self::SET_MEDIA,
				self::PROVIDER_DEFINED,
			),
			true
		);
	}
	public static function requiresFieldPath( string $type ): bool {
		return self::writesField( $type );
	}
	public static function createsFutureTarget( string $type ): bool {
		unset( $type );

		return false;
	}
	public static function destructive( string $type ): bool {
		unset( $type );

		return false;
	}
	public static function mutatesTarget( string $type ): bool {
		return ! in_array(
			$type,
			array(
				self::CAPTURE_SNAPSHOT,
				self::CLEAR_CACHE,
			),
			true
		);
	}
	public static function externalSideEffect( string $type ): bool {
		unset( $type );

		return false;
	}
}
