<?php

namespace App\Classes\Modules\Companies\Services;


use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Http\Resources\CompanyResource;
use App\Http\Resources\CurrencyResource;
use App\Models\Currency;
use App\Models\SegmentConstant;

class AddCurrenciesResourceToSupplierCompany
{

    public function execute(CompanyResource $company){

        if($company->business_type === BusinessType::CURRENCY_VENDOR){
            $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $company->id)->first();

            return ['currencies' => CurrencyResource::collection($segment ? Currency::whereIn('id', $segment->detail->currencies)->get() : [])];
        }

        return [];
    }

}