<?php

namespace Bixo\Account\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class TransactionResource extends JsonResource
{

    public function itemLink()
    {
        return guard_url('account/transaction') . '/' . $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,
            'type' => $this->type,
            'customer_id' => $this->customer_id,
            'supplier_id' => $this->supplier_id,
            'coa_id' => $this->coa_id,
            'customer_name' => $this->customer_name,
            'supplier_name' => $this->supplier_name,
            'coa_name' => $this->coa_name,
            'ref' => $this->ref,
            'mode' => $this->mode,
            'date' => $this->date,
            'currency' => $this->currency,
            'currency_rate' => $this->currency_rate,
            'currency_amount' => $this->currency_amount,
            'bank_id' => $this->bank_id,
            'cheque_bank' => $this->cheque_bank,
            'cheque_no' => $this->cheque_no,
            'cheque_date' => $this->cheque_date,
            'cheque_clear_date' => $this->cheque_clear_date,
            'cheque_status' => $this->cheque_status,
            'amount' => $this->amount,
            'tax' => $this->tax,
            'remarks' => $this->remarks,
            'details' => $this->details,
            'status' => $this->status,
            '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;
    }
}