<?php

namespace Modules\Internal\Transformers;

use Illuminate\Http\Resources\Json\JsonResource;

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

        $organization = [
            'id' => $this->id,
            'name' => $this->name,
            'type' => $this->type,
            'code' => $this->code,
            'description' => $this->description,
            'kodeRs' => $this->meta->KodeRS ?? null,
            'phone' => $this->meta->phone ?? null,
            'lat' => $this->currentAddress->lat ?? null,
            'lng' => $this->currentAddress->lng ?? null,
            'address' => $this->currentAddress->text ?? null,
            'province_id' => $this->currentAddress->province_id ?? null,
            'city_id' => $this->currentAddress->city_id ?? null,
            'district_id' => $this->currentAddress->district_id ?? null,
            'village_id' => $this->currentAddress->village_id ?? null,
            'postal_code' => $this->currentAddress->postal_code ?? null,
            'corporate_id_partner' => $this->corporate_id_partner ?? null,
            'active' => $this->status == 'active' ? 1 : 0,
        ];

        return $organization;
    }
}
