<?php 

namespace BwWinnersGlobalSite\Entities;

if ( ! class_exists( __NAMESPACE__ . '\Entity_Cache' ) ) {

	class Entity_Cache {

		private $group = 'bw_winners_v2';
		
		private $brand_prefix = 'bw_brand';
		
		private $product_prefix = 'bw_product';
		
		private $competition_prefix = 'bw_competition';


		// ----------------------------------------------------------------------------
		// Brand
		// ----------------------------------------------------------------------------

		public function get_brand ( $brand_id ) {
			return wp_cache_get( "{$this->brand_prefix}_{$brand_id}", $this->group );
		}

		public function set_brand ( $brand ) {

			if ( ! isset( $brand['id'] ) ) {
				return false;
			}

			return wp_cache_set( "{$this->brand_prefix}_{$brand['id']}", $brand, $this->group );
		}

		public function delete_brand ( $brand_id ) {
			return wp_cache_delete( "{$this->brand_prefix}_{$brand_id}", $this->group );
		}


		// ----------------------------------------------------------------------------
		// Product
		// ----------------------------------------------------------------------------

		public function get_product ( $product_id ) {
			return wp_cache_get( "{$this->product_prefix}_{$product_id}", $this->group );
		}

		public function set_product ( $product ) {

			if ( ! isset( $product['id'] ) ) {
				return false;
			}

			return wp_cache_set( "{$this->product_prefix}_{$product['id']}", $product, $this->group );
		}

		public function delete_product ( $product_id ) {
			return wp_cache_delete( "{$this->product_prefix}_{$product_id}", $this->group );
		}


		// ----------------------------------------------------------------------------
		// Competition
		// ----------------------------------------------------------------------------

		public function get_competition ( $competition_id ) {
			return wp_cache_get( "{$this->competition_prefix}_{$competition_id}", $this->group );
		}

		public function set_competition ( $competition ) {

			if ( ! isset( $competition['id'] ) ) {
				return false;
			}

			return wp_cache_set( "{$this->competition_prefix}_{$competition['id']}", $competition, $this->group );
		}

		public function delete_competition ( $competition_id ) {
			return wp_cache_delete( "{$this->competition_prefix}_{$competition_id}", $this->group );
		}


		// ----------------------------------------------------------------------------
		// Flush
		// ----------------------------------------------------------------------------

		public function flush_cache () {
			wp_cache_flush_group( $this->group );
		}
	}
}


