<?php

declare(strict_types=1);

namespace App\Http\Resources\Api\V1;

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

class EmailAccountResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'account_id' => $this->account_id,
            'email' => $this->email,        // virtual accessor: local@domain
            'local' => $this->local,
            'domain' => $this->domain,
            'quota_mb' => $this->quota_mb,
            'usage_bytes' => $this->usage_bytes,
            'usage_pct' => $this->usagePercent(),
            'status' => $this->status,
            'created_at' => $this->created_at?->toIso8601String(),
            'links' => [
                'self' => route('api.v1.email-accounts.show', $this->id),
            ],
        ];
    }
}
