<?php

namespace Modules\User\Resources\Api;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\School\Resources\Api\SchoolResource;

class ChildrenResource extends JsonResource
{

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => (int) $this->id,
            'cash_per_day' => (int) $this->cash_per_day,
            'remainingCash' => (int) $this->remainingCashToday(),
            'spentCash' => (int) $this->cash_per_day - $this->remainingCashToday(),
            'name' => $this->name,
            'gender' => $this->gender,
            'photo' => $this->photo ? asset($this->photo) : null,
            'bracelet_token' => $this->bracelet_token??$this->id,
            'active' => $this->active,
            'school' => new SchoolResource($this->school),
            'parent' => new UserResource($this->parent),
        ];
    }

}
