<?php

namespace App\Http\Resources;

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

/**
 * @mixin PlatformChannel
 */
class PlatformChannelResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'platform_instance_id' => $this->platform_instance_id,
            'channel_id' => $this->channel_id,
            'name' => $this->name,
            'display_name' => $this->display_name,
            'description' => $this->description,
            'language_id' => $this->language_id,
            'is_active' => $this->is_active,
            'created_at' => $this->created_at->toISOString(),
            'updated_at' => $this->updated_at->toISOString(),
            'platform_instance' => new PlatformInstanceResource($this->whenLoaded('platformInstance')),
            'platform_accounts' => PlatformAccountResource::collection($this->whenLoaded('platformAccounts')),
            'routes' => RouteResource::collection($this->whenLoaded('routes')),
        ];
    }
}
