<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class InvoiceResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'              => $this['cr6f2_invoiceid'],
            'doc_type'        => $this['cr6f2_maindoctype']               ?? null,
            'doc_name'        => $this['cr6f2_docuementtype']              ?? null, // filename stored here
            'invoice_number'  => $this['cr6f2_invoicenumber']             ?? null,
            'date'            => $this['cr6f2_date']                       ?? null,
            'total_amount'    => $this['cr6f2_totalamount']                ?? null,
            'currency'        => $this['cr6f2_vendorcurrecycodedraft']     ?? null,
            'document_type'   => $this['cr6f2_docuementtype']               ?? null,
            'vendor_name'     => $this['cr6f2_vendornamedraft']            ?? null,
            'vendor_address'  => $this['cr6f2_vendoraddressdraft']         ?? null,
            'description'     => $this['cr6f2_description']                ?? null,
            'credit_note'     => $this['cr6f2_creditnotenumber']           ?? null,
            'autocount_docno' => $this['cr6f2_autocountdocno']             ?? null,
            'exported_ac'     => $this['cr6f2_exporttoautocount']          ?? false,
            'exported_excel'  => $this['cr6f2_exporttoexcel']              ?? false,
            'reject_reason'   => $this['cr6f2_rejectreason']               ?? null,
            'review_comment'  => $this['_document']['cr6f2_reviewcomment'] ?? null,
            'document_link'   => $this['_document']['cr6f2_documentlink']  ?? null,
            'customer_id'     => $this['_cr6f2_customerid_value']          ?? null,
            'vendor_id'       => $this['_cr6f2_debtorcreditormapping_value'] ?? null,
            'uploaded_by'      => $this['_cr6f2_uploadedbyappuser_value'] ?? $this['_cr6f2_uploadedby_value']                                             ?? null,
            'uploaded_by_name' => $this['_cr6f2_uploadedbyappuser_value@OData.Community.Display.V1.FormattedValue'] ?? $this['_cr6f2_uploadedby_value@OData.Community.Display.V1.FormattedValue'] ?? null,
            'file_upload_date' => $this['cr6f2_fileuploaddate']                                              ?? null,
            'is_active'       => ($this['statecode'] ?? 1) === 0,
            'created_at'      => $this['createdon']                        ?? null,
            'modified_at'     => $this['modifiedon']                       ?? null,
        ];
    }
}
