<?php
/**
 * Image service interface for PDFDraft.
 *
 * @package PDFDraft
 */

namespace PDFDraft\Contracts\Services;

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

/**
 * Defines the contract for image service implementations.
 */
interface ImageServiceInterface {
	/**
	 * Save image.
	 *
	 * @param string $basename  Filename without extension.
	 * @param string $content   Image content.
	 * @param string $extension File extension.
	 * @return string|false URL on success or false on failure.
	 */
	public function save( string $basename, string $content, string $extension = 'png' );

	/**
	 * Delete image.
	 *
	 * @param string $basename  Filename without extension.
	 * @param string $extension File extension.
	 * @return bool True on success and false on failure.
	 */
	public function delete( string $basename, string $extension = 'png' ): bool;

	/**
	 * Get URL of image.
	 *
	 * @param string $basename  Filename without extension.
	 * @param string $extension File extension.
	 * @return string|false URL or false if not found.
	 */
	public function getUrl( string $basename, string $extension = 'png' );

	/**
	 * Check if image exists.
	 *
	 * @param string $basename  Filename without extension.
	 * @param string $extension File extension.
	 * @return bool
	 */
	public function exists( string $basename, string $extension = 'png' ): bool;

	/**
	 * Store image from request data.
	 *
	 * @param \WP_Post             $post    Post object.
	 * @param array<string, mixed> $request Request data containing image.
	 * @return void
	 */
	public function storeFromRequest( \WP_Post $post, array $request ): void;

	/**
	 * Get image size in bytes.
	 *
	 * @param string $basename  Filename without extension.
	 * @param string $extension File extension.
	 * @return int|false Size in bytes or false if not found.
	 */
	public function getSize( string $basename, string $extension = 'png' );

	/**
	 * Get image modification timestamp.
	 *
	 * @param string $basename  Filename without extension.
	 * @param string $extension File extension.
	 * @return int|false Unix timestamp or false if not found.
	 */
	public function getModifiedAt( string $basename, string $extension = 'png' );

	/**
	 * Process and save image from base64 data URL.
	 *
	 * @param string $basename Filename without extension.
	 * @param string $dataUrl  Base64 data URL.
	 * @return array|false Array with image info on success, false on failure.
	 */
	public function saveFromDataUrl( string $basename, string $dataUrl );
}
