<?php

namespace App\Classes\Modules\Exports\Services;

use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Models\Company;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithMapping;

class ExportsProducts implements FromQuery, WithHeadingRow, WithMapping
{

    use Exportable;

    public function headings(): array
    {
        return [
            'HS Code',
            'Name',
            'price'
        ];
    }

    /**
     * @return \Illuminate\Support\Collection|mixed
     */
    public function query()
    {
        return \App\Models\TransactionDetail::inRandomOrder()->whereHas('transaction', function($query){
            return $query->where('type', \App\Classes\ValueObjects\Constants\TransactionType::PURCHASE_ORDER)->where('status', ApprovalStatus::APPROVED);
        })->limit(50);
    }

    /**
     * @param $product
     * @return array
     */
    public function map($product): array
    {

        return [
            $product->product_code,
            $product->product_name,
            $product->price,
        ];
    }
}