<?php

namespace App\Http\Resources;

use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Wallet;
use Illuminate\Http\Resources\Json\JsonResource;

class MappableTransactionResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $reference = null;
        if($this->type === TransactionType::TOP_UP) {
            $reference = $this->owner->owner->reference;
        }

        if($this->type === TransactionType::PAYMENT && $this->owner !== Wallet::class){
            $reference =  $this->owner->marking;
        }

        return [
            'status' => 'success',
            'system' => 'EXCHANGE',
            'type' => $this->type,
            'owner_type' => $this->owner_type,
            'owner_id'=> $this->id,
            'owner_reference'=> $reference,
        ];
    }
}
