<?php

namespace App\Services;

use App\Models\CustomPrice;
use App\Models\User;

class NumberService
{
    public static function customPrice(User $user, string $serviceId, string $serverId, float $price): float
    {
        $cp = CustomPrice::where('user_id', $user->id)
            ->where('service_id', $serviceId)
            ->where('server_id', $serverId)
            ->first();

        if (!$cp) {
            return $price;
        }
        if ($cp->type === 'flat') {
            return (float) $cp->discount;
        }
        if ($cp->type === 'percent') {
            $deduct = ($cp->discount / 100) * $price;
            return $price - $deduct;
        }
        return $price;
    }
}