<?php

namespace App\Http\Resources\Api\V1;

use App\Domain\Memory\Models\Memory;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/** @mixin Memory */
class MemoryResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'agent_id' => $this->agent_id,
            'project_id' => $this->project_id,
            'content' => $this->content,
            'source_type' => $this->source_type,
            'source_id' => $this->source_id,
            'metadata' => $this->metadata,
            'tags' => $this->tags,
            'confidence' => $this->confidence,
            'belief_type' => $this->belief_type?->value,
            'preference_subtype' => $this->preference_subtype?->value,
            'why_it_matters' => $this->why_it_matters,
            'belief_status' => $this->belief_status->value,
            'domain' => $this->domain,
            'rejected_alternatives' => $this->rejected_alternatives ?? [],
            'supersedes_id' => $this->supersedes_id,
            'conflict_flag' => (bool) $this->conflict_flag,
            'conflict_with_id' => $this->conflict_with_id,
            'conflict_detected_at' => $this->conflict_detected_at?->toISOString(),
            'created_at' => $this->created_at->toISOString(),
            'updated_at' => $this->updated_at->toISOString(),
        ];
    }
}
