<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class MeetingResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'project_id' => $this->project_id,
            'project' => new ProjectResource($this->whenLoaded('project')),
            'sprint_id' => $this->sprint_id,
            'sprint' => new SprintResource($this->whenLoaded('sprint')),
            'meeting_type_id' => $this->meeting_type_id,
            'type' => $this->whenLoaded('type'),
            'date' => $this->date?->format('Y-m-d'),
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'location' => $this->location,
            'meeting_link' => $this->meeting_link,
            'meeting_type' => $this->meeting_type,
            'status' => $this->status ?? 'scheduled',
            'objective' => $this->objective,
            'agenda' => $this->agenda,
            'notes' => $this->notes,
            'summary' => $this->summary,
            'decisions' => $this->decisions,
            'structured_decisions' => $this->whenLoaded('structuredDecisions'),
            'structured_action_items' => $this->whenLoaded('structuredActionItems'),
            'blockers' => $this->whenLoaded('blockers'),
            'files' => FileResource::collection($this->whenLoaded('files')),
            'participants' => UserResource::collection($this->whenLoaded('participants')),
            'action_items' => MeetingActionItemResource::collection($this->whenLoaded('actionItems')),
            'created_by' => $this->created_by,
            'creator' => new UserResource($this->whenLoaded('creator')),
            'owner_id' => $this->owner_id,
            'owner' => new UserResource($this->whenLoaded('owner')),
            'facilitator_id' => $this->facilitator_id,
            'facilitator' => new UserResource($this->whenLoaded('facilitator')),
            'reminder_minutes' => $this->reminder_minutes,
            'recurrence_rule' => $this->recurrence_rule,
            'started_at' => $this->started_at,
            'completed_at' => $this->completed_at,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
