<?php

namespace App\Http\Resources;

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

class ExpenseResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'company_id' => $this->company_id,
            'branch_id' => $this->branch_id,
            'shift_id' => $this->shift_id,
            'expense_category_id' => $this->expense_category_id,
            'user_id' => $this->user_id,
            'amount' => $this->amount,
            'description' => $this->description,
            'payment_method' => $this->payment_method,
            'reference' => $this->reference,
            'receipt_url' => $this->receipt_url,
            'expense_date' => $this->expense_date,
            'is_approved' => $this->is_approved,
            'approved_by' => $this->approved_by,
            'approved_at' => $this->approved_at,
            'device_id' => $this->device_id,
            'synced_at' => $this->synced_at,
            'created_at' => $this->created_at,
            'category' => $this->whenLoaded('category', fn () => $this->category?->only(['id', 'name'])),
            'user' => $this->whenLoaded('user', fn () => $this->user?->only(['id', 'name'])),
            'approver' => $this->whenLoaded('approver', fn () => $this->approver?->only(['id', 'name'])),
        ];
    }
}
