<?php

namespace App\Http\Resources;

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

class BoardResource extends JsonResource
{
    public function toArray($request)
    {
        $users = [];
        $userDetails = [];

        foreach ($this->users as $user) {
            $users[] = $user->id;
            $userDetails[] = [
                'id' => $user->id,
                'profile' => $user->profile(),
            ];
        }

        return [
            'id' => $this->id,
            'code' => $this->code,
            'bg_color' => $this->bg_color,
            'text_color' => $this->text_color,
            'title' => $this->title,
            'description' => $this->description,
            'users' => $users,
            'userDetails' => $userDetails,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'buckets' => BucketResource::collection($this->buckets),
        ];
    }
}
