<?php

namespace Bixo\Account\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class AcknowledgementResource extends JsonResource
{

    public function itemLink()
    {
        return guard_url('account/acknowledgement') . '/' . $this->getRouteKey();
    }

    public function title()
    {
        if ($this->title != '') {
            return $this->title;
        }

        if ($this->name != '') {
            return $this->name;
        }

        return 'None';
    }

    public function toArray($request)
    {
        return [
            'id' => $this->getRouteKey(),
            'title' => $this->title(),
            'slug' => $this->slug,
            'company_id' => $this->company_id,
            'customer_id' => $this->customer_id,
            'coa_id' => $this->coa_id,
            'agent_id' => $this->agent_id,
            'ref' => $this->ref,
            'unit' => $this->unit,
            'date' => $this->date,
            'project_name' => $this->project_name,
            'building' => $this->building,
            'project_price' => $this->project_price,
            'amount' => $this->amount,
            'currency' => $this->currency,
            'remarks' => $this->remarks,
            'status' => $this->status,
            'type' => $this->type,
            'deal_customer_type' => $this->deal_customer_type,
            'user_id' => $this->user_id,
            'created_at' => !is_null($this->created_at) ? $this->created_at->format('Y-m-d H:i:s') : null,
            'updated_at' => !is_null($this->updated_at) ? $this->updated_at->format('Y-m-d H:i:s') : null,
            'meta' => [
                'exists' => $this->exists(),
                'link' => $this->itemLink(),
                'upload_url' => $this->getUploadURL(''),
                'workflow' => $this->workflows(),
                'actions' => $this->actions(),
            ],
        ];
    }

    /**
     * Get additional data that should be returned with the resource array.
     *
     * @param     \Illuminate\Http\Request  $request
     * @return array
     */
    public function with($request)
    {
        return [
            'meta' => [
                'exists' => $this->exists(),
                'link' => $this->itemLink(),
                'upload_url' => $this->getUploadURL(''),
                'workflow' => $this->workflows(),
                'actions' => $this->actions(),
            ],
        ];
    }

    /**
     * Get the workflows for the resource.
     *
     * @return array
     */
    private function workflows()
    {
        $arr = [];
                return $arr;

    }
    
    /**
     * Get the actions for the resource.
     *
     * @return array
     */
    private function actions()
    {

        $arr = [];
        
        return $arr;
    }
}