<?php

namespace App\Models;

use App\Traits\HasCacheModel;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\TFirstDefault;
use Illuminate\Support\TValue;

class DiscountType extends Model
{
    use HasFactory;
    use HasCacheModel;

    const PERCENT = 2;
    const PRICE = 1;

    public function __construct()
    {
        $this->table = 'discount_type';
    }

    static public function getUnit($discount)
    {
        return self::getByCache()
            ->where('id', $discount->discount_type_id)
            ->value('unit');
    }
}
