<?php
namespace App\Services\Product\Tax;

use App\Models\Cart;
use App\Models\Product;
use App\Models\Setting;
use App\Services\Auth\User\AccountService;
use App\Services\Currency\CurrencyService;
use App\Services\Product\ProductService;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;

class TaxService
{
    public static function tax($total=0)
    {
        $tax_valid = Setting::where('key','tax_valid')->first()->value;
        if($tax_valid == 'false')
        {
            return
            [
                'valid' => false,
                'value' => 0,
            ];
        }
        $tax_value = Setting::where('key','tax_value')->first()->value;
        $status = Setting::where('key','tax_status')->first()->value;
        
        if($status == 'percentage')
        {
            $tax_value = ($tax_value/100) * $total;
        }
        else
        {
            $currency =(new CurrencyService())->getCurrency();
            $tax_value = $tax_value * $currency->currency;
        }
        $tax_value =  round($tax_value,2);
        
        return[
            'valid' => true,
            'value' =>$tax_value,
        ];
    }
}
