<?php
/**
 * Review Entity
 *
 * @package Ugcify\Review
 */

namespace Ugcify\Review;

/**
 * Class Review
 */
class Review {
	/**
	 * Review ID
	 *
	 * @var int
	 */
	public $id;

	/**
	 * User ID (null for guest users)
	 *
	 * @var int|null
	 */
	public $user_id;

	/**
	 * Guest name (for non-logged-in users)
	 *
	 * @var string|null
	 */
	public $guest_name;

	/**
	 * Guest email (for non-logged-in users)
	 *
	 * @var string|null
	 */
	public $guest_email;

	/**
	 * Product ID
	 *
	 * @var int
	 */
	public $product_id;

	/**
	 * Rating (1-5)
	 *
	 * @var int
	 */
	public $rating;

	/**
	 * Review content
	 *
	 * @var string
	 */
	public $content;

	/**
	 * Review status: pending, approved, rejected
	 *
	 * @var string
	 */
	public $status;

	/**
	 * Featured flag
	 *
	 * @var int
	 */
	public $is_featured;

	/**
	 * Pinned flag
	 *
	 * @var int
	 */
	public $is_pinned;

	/**
	 * Review type: text, image, video, mixed
	 *
	 * @var string
	 */
	public $type;

	/**
	 * Points awarded
	 *
	 * @var int
	 */
	public $points;

	/**
	 * Created timestamp
	 *
	 * @var string
	 */
	public $created_at;

	/**
	 * Updated timestamp
	 *
	 * @var string
	 */
	public $updated_at;

	/**
	 * Dynamic rendering properties (attached by templates)
	 *
	 * @var mixed
	 */
	public $_ugcify_meta;
	public $_ugcify_thumbnail;
	public $_ugcify_story_has_video;
	public $_ugcify_media;

	/**
	 * Constructor
	 *
	 * @param array $data Review data.
	 */
	public function __construct( array $data = array() ) {
		$this->id          = isset( $data['id'] ) ? (int) $data['id'] : null;
		$this->user_id     = isset( $data['user_id'] ) && $data['user_id'] ? (int) $data['user_id'] : null;
		$this->guest_name  = isset( $data['guest_name'] ) ? $data['guest_name'] : null;
		$this->guest_email = isset( $data['guest_email'] ) ? $data['guest_email'] : null;
		$this->product_id  = isset( $data['product_id'] ) ? (int) $data['product_id'] : null;
		$this->rating      = isset( $data['rating'] ) ? (int) $data['rating'] : null;
		$this->content     = isset( $data['content'] ) ? $data['content'] : '';
		$this->status      = isset( $data['status'] ) ? $data['status'] : 'pending';
		$this->is_featured = isset( $data['is_featured'] ) ? (int) $data['is_featured'] : 0;
		$this->is_pinned   = isset( $data['is_pinned'] ) ? (int) $data['is_pinned'] : 0;
		$this->type        = isset( $data['type'] ) ? $data['type'] : 'text';
		$this->points      = isset( $data['points'] ) ? (int) $data['points'] : 0;
		$this->created_at  = isset( $data['created_at'] ) ? $data['created_at'] : null;
		$this->updated_at  = isset( $data['updated_at'] ) ? $data['updated_at'] : null;
	}

	/**
	 * Convert review to array for database operations
	 *
	 * @return array
	 */
	public function to_array() {
		return array(
			'id'          => $this->id,
			'user_id'     => $this->user_id,
			'guest_name'  => $this->guest_name,
			'guest_email' => $this->guest_email,
			'product_id'  => $this->product_id,
			'rating'      => $this->rating,
			'content'     => $this->content,
			'status'      => $this->status,
			'is_featured' => $this->is_featured,
			'is_pinned'   => $this->is_pinned,
			'type'        => $this->type,
			'points'      => $this->points,
			'created_at'  => $this->created_at,
			'updated_at'  => $this->updated_at,
		);
	}
}
