<?php

namespace App\Http\Resources\Notifications;

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

class UserNotificationResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $scheduledAt = $this->scheduled_at ?? $this['scheduled_at'] ?? null;
        $expiresAt = $this->expires_at ?? $this['expires_at'] ?? null;

        return [
            'notification_id' => (int) ($this->notification_id ?? $this['notification_id'] ?? 0),
            'title' => $this->title ?? $this['title'] ?? null,
            'message' => $this->message ?? $this['message'] ?? null,
            'priority' => $this->priority ?? $this['priority'] ?? null,
            'scheduled_at' => $scheduledAt ? date('Y-m-d H:i:s', strtotime((string) $scheduledAt)) : null,
            'expires_at' => $expiresAt ? date('Y-m-d H:i:s', strtotime((string) $expiresAt)) : null,
            'target_group' => $this->target_group ?? $this['target_group'] ?? null,
            'is_read' => (bool) ($this->is_read ?? $this['is_read'] ?? false),
        ];
    }
}
