<?php
/**
 * Base DTO
 *
 * @category   WordPress_Plugin
 * @package    Common
 * @subpackage Abstracts
 * @author     miniOrange <info@miniorange.com>
 * @license    MIT/Expat
 * @link       https://plugins.miniorange.com/woocommerce-api-product-sync-with-woocommerce-rest-apis
 */

namespace MOWCPS\Common\Abstracts;

use WP_Error;
use MOWCPS\Common\Constants\Constants;

/**
 * Class Base_DTO
 *
 * Base DTO class for all DTOs
 */
abstract class Base_DTO {
	/**
	 * Validate UUID
	 *
	 * @param string $uuid UUID to validate.
	 * @param string $field_name Field name for error messages.
	 * @return true|WP_Error True if valid, WP_Error if invalid
	 */
	public static function validate_uuid( $uuid, $field_name = 'uuid' ) {
		if ( empty( $uuid ) ) {
			return new WP_Error(
				Constants::ERROR_MISSING_REQUIRED_FIELD,
				sprintf( Constants::MSG_MISSING_REQUIRED_FIELD, $field_name ),
				array( 'status' => Constants::HTTP_BAD_REQUEST )
			);
		}

		return true;
	}

	/**
	 * Create instance from request parameters
	 *
	 * @param array $params Request parameters.
	 * @return self|WP_Error Instance or error if validation fails
	 */
	abstract public static function from_request_parameters( $params );

	/**
	 * Validate the request data
	 *
	 * @return self|WP_Error Instance if valid, WP_Error if invalid
	 */
	abstract protected function validate();
}
