<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
	/**
	 * Transform the resource into an array.
	 *
	 * @param \Illuminate\Http\Request $request
	 * @return array
	 */
	public function toArray($request)
	{
		return [
			'id'                  => $this->id,
			'name'                => $this->name,
			'username'            => $this->username,
			'first_name'          => $this->first_name,
			'last_name'           => $this->last_name,
			'full_name'           => $this->full_name,
			'furigana_first_name' => $this->furigana_first_name,
			'furigana_last_name'  => $this->furigana_last_name,
			'furigana_name'       => $this->furigana_name,
			'avatar'              => ($this->avatar != null && $this->avatar != "") ? $this->avatar : 'avatar.png',
			'post_code'           => $this->post_code,
			'city'                => $this->city,
			'district'            => $this->district,
			'address'             => $this->address,
			'address2'            => $this->address2,
			'shipping_post_code'  => $this->shipping_post_code,
			'shipping_city'       => $this->shipping_city,
			'shipping_district'   => $this->shipping_district,
			'shipping_address'    => $this->shipping_address,
			'shipping_address2'   => $this->shipping_address2,
			'phone_number'        => $this->phone_number,
			'fax_number'          => $this->fax_number,
			'mobile_tel'          => $this->mobile_tel,
			'emg_tel'             => $this->emg_tel,
			'email'               => $this->email,
			'email2'              => $this->email2,
			'gender'              => $this->gender,
			'height'              => $this->height,
			'sleeve'              => $this->sleeve,
			'waist'               => $this->waist,
			'career'              => $this->career,
			'date_of_birth'       => $this->date_of_birth,
			'reminder_question'   => $this->reminder_question,
			'reminder_answer'     => $this->reminder_answer,
			'email_subscribe'     => $this->email_subscribe,
			'email_format'        => $this->email_format,
			'driver_license'      => $this->driver_license,
			'insurance_card'      => $this->insurance_card,
			'number_card'         => $this->number_card,
			'verify_card'         => $this->verify_card,
			'identity_status'     => $this->identity_status ?? 'not_submitted',
			'identity_rejection_count' => $this->identity_rejection_count ?? 0,
			'point'               => $this->point,
			'point_rate'          => $this->point_rate,
			'introduction'        => $this->introduction,
			'bank_name'           => $this->bank_name,
			'bank_code'           => $this->bank_code,
			'bank_branch_name'    => $this->bank_branch_name,
			'bank_branch_code'    => $this->bank_branch_code,
			'bank_account_type'   => $this->bank_account_type,
			'bank_account_number' => $this->bank_account_number,
			'bank_holder_name'    => $this->bank_holder_name,
			'language'            => 'ja',
			'created_by'          => $this->created_by,
			'cards'               => $this->cards,
			'types'               => array_map(
				function ($type) {
					return $type['type'];
				},
				$this->types->toArray()
			),
			'roles'               => array_map(
				function ($role) {
					return $role['name'];
				},
				$this->roles->toArray()
			),
			'permissions'         => array_map(
				function ($permission) {
					return $permission['name'];
				},
				$this->getAllPermissions()->toArray()
			),
		];
	}
}
