<?php

namespace AutomateWoo\DataTypes;

use WP_Post;

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

/**
 * Post data type class.
 */
class Post extends AbstractDataType {

	/**
	 * @param mixed $item
	 * @return bool
	 */
	public function validate( $item ) {
		return $item instanceof WP_Post;
	}


	/**
	 * @param WP_Post $item
	 * @return mixed
	 */
	public function compress( $item ) {
		return $item->ID;
	}


	/**
	 * @param int|string|null $compressed_item
	 * @param array           $compressed_data_layer
	 * @return mixed
	 */
	public function decompress( $compressed_item, $compressed_data_layer ) {
		if ( ! $compressed_item ) {
			return false;
		}

		return get_post( $compressed_item );
	}
}
