<?php
namespace Miruni\DraftManager;

class MiruniChangeResult
{
    // Properties are defined via constructor property promotion below

    public function __construct(
        public string $fileName,
        public string $changesMade,
        public string $originalContent,
        public string $fileIdentifier,
        public string $fileType, // Use string type hint
        public int $suggestionId = 0,
        public ?int $referencedPostId = null,
        /** @var ?array{post_id: int, post_title: string, post_content: string} */
        public ?array $post = null,
        public ?string $updatedFileContent = null
    ) {
        // Assignments are handled by constructor property promotion
    }

    /**
     * Converts the object to an associative array.
     *
     * @return array{
     *  file_name: string,
     * changes_made: string,
     * original_content: string,
     * file_identifier: string,
     * file_type: string,
     * referenced_post_id?: int|null,
     * suggestion_id: int,
     *   post?: array{
     *   post_id: int,
     *   post_title: string,
     *   post_content: string
     *  } | null,
     * updated_file_content?: string|null
     * }
     */
    public function to_array(): array
    {
        return [
            'file_name' => $this->fileName,
            'changes_made' => $this->changesMade,
            'original_content' => $this->originalContent,
            'file_identifier' => $this->fileIdentifier,
            'file_type' => $this->fileType,
            'suggestion_id' => $this->suggestionId,
            'referenced_post_id' => $this->referencedPostId,
            'post' => $this->post,
            'updated_file_content' => $this->updatedFileContent,
        ];
    }

    /**
     * Summary of set_post_data
     * @param array<mixed> $post_data
     * @return void
     */
    public function set_post_data(array $post_data): void
    {
        $this->post = [
            'post_id' => $post_data['post_id'],
            'post_title' => $post_data['post_title'],
            'post_content' => $post_data['post_content'],
        ];
    }

    public function set_referenced_post_id(?int $post_id): void
    {
        $this->referencedPostId = $post_id;
    }
}