<?php

namespace App\Http\Resources;

use App\Models\PlatformAccount;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @mixin PlatformAccount
 */
/**
 * @mixin PlatformAccount
 */
class PlatformAccountResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'platform' => $this->platform->value,
            'instance_url' => $this->instance_url,
            'username' => $this->username,
            'settings' => $this->settings,
            'is_active' => $this->is_active,
            'last_tested_at' => $this->last_tested_at?->toISOString(),
            'status' => $this->status,
            'created_at' => $this->created_at->toISOString(),
            'updated_at' => $this->updated_at->toISOString(),
            'channels' => PlatformChannelResource::collection($this->whenLoaded('channels')),
        ];
    }
}
