<?php

namespace Modules\SpecialAttendance\Transformers;

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

class DeductionResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        // return parent::toArray($request);

        return [
            'id' => $this->id,
            'month' => Carbon::parse($this->year.'-'.$this->month)->format('M Y'),
            'amount' => $this->amount,
            'consider_amount' => $this->consider_amount,
            'appeal_enable' => $this->is_appealed ? 0 : (Carbon::parse($this->created_at)->addDays(2)->format('Y-m-d') >= date('Y-m-d') ? 1 : 0),
            'is_appealed' => $this->is_appealed ? _trans('common.Yes') : _trans('common.No'),
            'appealed_at' => $this->appealed_at ? Carbon::parse($this->appealed_at)->format('Y-m-d h:i A') : null,
            'appeal_approved_by' => @$this->appealApprovedBy->name ?? null,
            'appeal_approved_at' => $this->appeal_approved_at ? Carbon::parse($this->appeal_approved_at)->format('Y-m-d h:i A') : null,
            'appeal_status' => @$this->appealStatus->name ?? null,
            'deduction_details' => DeductionDetailResource::collection($this->whenLoaded('deductionDetails')),
        ];
    }
}
