<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

/** @mixin \App\Models\Service */
class AdminServiceResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'user' => $this->whenLoaded('user', fn () => [
                'id' => $this->user->id,
                'name' => $this->user->name,
                'email' => $this->user->email,
            ]),
            'service_type' => $this->service_type,
            'platform' => $this->platform,
            'platform_service_id' => $this->platform_service_id,
            'status' => $this->status,
            'hostname' => $this->hostname,
            'ipv4_address' => $this->ipv4_address,
            'plan' => $this->whenLoaded('plan', fn () => [
                'id' => $this->plan->id,
                'name' => $this->plan->name,
                'price' => $this->plan->price,
                'billing_cycle' => $this->plan->billing_cycle,
            ]),
            'provisioned_at' => $this->provisioned_at,
            'suspended_at' => $this->suspended_at,
            'terminated_at' => $this->terminated_at,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
