<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use App\Models\Provider;

class ProviderResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'document' => $this->document,
            'rg' => $this->rg,
            'user_id' => $this->user_id,
            'user' => $this->user,
            'average_rating' => $this->average_rating,
            'total_services' => $this->total_services,
            'birth_date' => $this->birth_date ? Carbon::parse($this->birth_date)->format('d/m/Y') : null,
            'selfie_verified' => $this->selfie_verified,
            'document_verified' => $this->document_verified,
            'approval_status' => $this->approval_status?->value ?? $this->approval_status,
            'daily_price_8h' => $this->daily_price_8h,
            'daily_price_6h' => $this->daily_price_6h,
            'daily_price_4h' => $this->daily_price_4h,
            'daily_price_2h' => $this->daily_price_2h,
            'profile_media_id' => $this->profile_media_id,
            'recipient_id' => $this->recipient_id,
            'profile_media' => $this->profileMedia,
            'created_at' => Carbon::parse($this->created_at)->format('d/m/Y H:i'),
            'updated_at' => Carbon::parse($this->updated_at)->format('d/m/Y H:i'),
        ];
    }

    /**
     * @param \Illuminate\Database\Eloquent\Collection<Provider> $resource
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<ProviderResource>
     */
    public static function collection($resource): AnonymousResourceCollection
    {
        return parent::collection($resource);
    }
}
