<?php

namespace Modules\TPConnector\Transformers;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\Resource;
use App\Utils\Util;

class SellResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request
     * @return array
     */
    public function toArray($request)
    {
        $commonUtil = new Util;
        return [
            'id' => $this->resource['id'],
            'business_id' => $this->resource['business_id'],
            'location_id' => $this->resource['location_id'],
            'res_table_id' => $this->resource['res_table_id'],
            'res_table_name' => optional($this->resource->table)->name,
            'payment_status' => $this->resource['payment_status'],
            'invoice_no' => $this->resource['invoice_no'],
            'transaction_date' => $this->resource['transaction_date'],
            'discount_type' => $this->resource['discount_type'],
            'discount_amount' => $this->resource['discount_amount'],
            'total_before_tax' => $this->resource['total_before_tax'],
            'tax_id' => $this->resource['tax_id'],
            'tax_amount' => $this->resource['tax_amount'],
            'shipping_status' => $this->resource['shipping_status'],
            'delivered_to' => $this->resource['delivered_to'],
            'additional_notes' => $this->resource['additional_notes'],
            'staff_note' => $this->resource['staff_note'],
            'final_total' => $this->resource['final_total'],
            'is_suspend' => $this->resource['is_suspend'],
            'custom_field_1' => $this->resource['custom_field_1'],
            'custom_field_2' => $this->resource['custom_field_2'],
            'custom_field_3' => $this->resource['custom_field_3'],
            'custom_field_4' => $this->resource['custom_field_4'],
            'created_at' => $this->resource['created_at'],
            'updated_at' => $this->resource['updated_at'],
            'invoice_url' => $commonUtil->getInvoiceUrl($this->resource['id'], $this->resource['business_id']),
            'sell_lines' => $this->resource->sell_lines->map->only([
                'id', 'transaction_id', 'product_id', 'variation_id', 'quantity',
                'created_at', 'updated_at',
            ]),
            'payment_lines' => $this->resource->payment_lines->map->only([
                'amount', 'method',
            ]),
            //'payment_link' => $commonUtil->getInvoicePaymentLink($this->resource['id'], $this->resource['business_id']),
        ];
    }
}
