<?php
/**
 * Create Reviews Table Migration.
 *
 * @package Ugcify
 */

namespace Ugcify\Database\Migrations;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * CreateReviewsTable migration class.
 */
class CreateReviewsTable {

	/**
	 * WordPress database instance.
	 *
	 * @var \wpdb
	 */
	private $wpdb;

	/**
	 * Constructor.
	 *
	 * @param \wpdb $wpdb WordPress database instance.
	 */
	public function __construct( $wpdb ) {
		$this->wpdb = $wpdb;
	}

	/**
	 * Run migration.
	 *
	 * @return string SQL statement.
	 */
	public function run() {
		$table_name      = $this->wpdb->prefix . 'ugcify_reviews';
		$charset_collate = $this->wpdb->get_charset_collate();

		return "CREATE TABLE $table_name (
			id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
			user_id BIGINT(20) UNSIGNED DEFAULT NULL,
			guest_name VARCHAR(255) DEFAULT NULL,
			guest_email VARCHAR(255) DEFAULT NULL,
			product_id BIGINT(20) UNSIGNED NOT NULL,
			rating TINYINT(1) UNSIGNED DEFAULT NULL,
			content LONGTEXT NOT NULL,
			status VARCHAR(20) NOT NULL DEFAULT 'pending',
			is_featured TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
			is_pinned TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
			type VARCHAR(20) NOT NULL DEFAULT 'text',
			points INT(11) NOT NULL DEFAULT 0,
			created_at DATETIME NOT NULL,
			updated_at DATETIME NOT NULL,
			PRIMARY KEY (id),
			KEY product_id (product_id),
			KEY user_id (user_id),
			KEY guest_email (guest_email),
			KEY status (status),
			KEY is_featured (is_featured),
			KEY is_pinned (is_pinned),
			KEY rating (rating),
			KEY type (type),
			KEY created_at (created_at)
		) $charset_collate;";
	}
}
