<?php

namespace App\Http\Resources;

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

class CurrentStatusResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'check_in_time' => $this->check_in
                ? Carbon::parse($this->check_in)->setTimezone('Asia/Jakarta')->format('H:i')
                : null,
            'check_out_time' => $this->check_out
                ? Carbon::parse($this->check_out)->setTimezone('Asia/Jakarta')->format('H:i')
                : null,
            'check_in_date' => $this->check_in
                ? Carbon::parse($this->check_in)->setTimezone('Asia/Jakarta')->format('d/m/y')
                : null,
            'check_out_date' => $this->check_out
                ? Carbon::parse($this->check_out)->setTimezone('Asia/Jakarta')->format('d/m/y')
                : null,
        ];
    }
}
