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

namespace Ugcify\Database\Migrations;

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

/**
 * CreateProductTagsTable migration class.
 */
class CreateProductTagsTable {
	/**
	 * 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_product_tags';
		$charset_collate = $this->wpdb->get_charset_collate();

		return "CREATE TABLE $table_name (
			id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
			media_id BIGINT(20) UNSIGNED NOT NULL,
			product_id BIGINT(20) UNSIGNED NOT NULL,
			x_coordinate FLOAT(10,6) NOT NULL,
			y_coordinate FLOAT(10,6) NOT NULL,
			custom_label VARCHAR(255) DEFAULT '' NOT NULL,
			source VARCHAR(20) DEFAULT 'manual' NOT NULL,
			ai_job_id BIGINT(20) UNSIGNED DEFAULT NULL,
			confidence FLOAT DEFAULT NULL,
			created_at DATETIME NOT NULL,
			updated_at DATETIME NOT NULL,
			PRIMARY KEY (id),
			KEY media_id (media_id),
			KEY product_id (product_id)
		) $charset_collate;";
	}
}
