<?php
namespace flow\social\publisher;
if (!defined('WPINC'))
	die;

/**
 * Instagram Publisher.
 *
 * Publishes photo and carousel posts to an Instagram Business/Creator
 * account via the Instagram Graph API (through Meta).
 *
 * Required permission: instagram_content_publish
 *
 * Two-step publish process:
 *   1. POST /{ig-user-id}/media       — create a media container
 *   2. POST /{ig-user-id}/media_publish — publish the container
 *
 * Constraints:
 *   - Images must be JPEG, aspect ratio between 4:5 and 1.91:1.
 *   - Carousel posts require 2–10 items.
 *
 * @package   FlowFlow
 * @author    Looks Awesome <email@looks-awesome.com>
 * @link      http://looks-awesome.com
 * @copyright Looks Awesome
 */
class FFInstagramPublisher extends FFBasePublisher {

	const API_VERSION = 'v19.0';

	public function getNetwork() {
		return 'instagram';
	}

	/**
	 * @inheritDoc
	 */
	public function publish(array $postData) {
		$this->token = isset($postData['token']) ? $postData['token'] : '';
		$accountId   = isset($postData['account_id']) ? $postData['account_id'] : '';

		if (empty($this->token) || empty($accountId)) {
			return $this->errorResult('Missing Instagram token or IG user ID.');
		}

		$this->log('Publishing to Instagram', [
			'account_id' => $accountId,
			'has_text'   => !empty($postData['text']),
			'has_media'  => !empty($postData['media']),
		]);

		// TODO: Implement actual API call when ready
		// Step 1: Create container  → POST /{ig-user-id}/media?image_url=...&caption=...
		// Step 2: Publish container → POST /{ig-user-id}/media_publish?creation_id=...

		return $this->errorResult('Instagram publishing is not yet implemented. API integration pending.');
	}
}
