<?php

namespace App\Models\Lookups;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;

class DiscountType extends Model
{
    use BelongsToTenant;

    public const PERCENTAGE = 'percentage';

    public const FIXED = 'fixed';

    protected $fillable = ['code', 'name', 'sort_order'];

    protected function casts(): array
    {
        return ['sort_order' => 'integer'];
    }

    public static function findByCode(string $code): ?self
    {
        return static::query()->where('code', $code)->first();
    }

    public static function idOf(string $code): ?int
    {
        return static::findByCode($code)?->id;
    }
}
