<?php

namespace Modules\Payroll\Transformers;

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

class EmployeeAdvanceResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'employee' => $this->whenLoaded('employee', function () {
                return [
                    'id' => $this->employee->id,
                    'name' => $this->employee->name,
                    'emp_number' => $this->employee->emp_number,
                    'phone' => $this->employee->phone,
                ];
            }),
            'advance_amount' => $this->advance_amount,
            'remaining_amount' => $this->remaining_amount,
            'installment_months' => $this->installment_months,
            'monthly_deduction' => $this->monthly_deduction,
            'paid_installments' => $this->paid_installments,
            'issue_date' => $this->issue_date,
            'advance_no' => $this->advance_no,
            'remarks' => $this->remarks,
            'status' => $this->status,
        ];
    }
}
