<?php

namespace Modules\User\Http\Resources;

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

class IdentityMiddleResource extends JsonResource
{

    public function toArray($request): array
    {
        if ($this->identity->order == 1) {
            $ended_at = '---';
        } else {
            $ended_at = $this->identity->years ? Carbon::parse($this->ended_at)->format('Y-m-d') : '永久';
        }

        return [
            'name'       => $this->identity->name,
            'serial'     => $this->identity->serial_prefix.$this->serial,
            'started_at' => (string)$this->started_at ?? '',
            'ended_at'   => $ended_at,
        ];
    }

}