<?php

namespace App\Models\Lookups;

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

class VoucherType extends Model
{
    use BelongsToTenant;

    public const GIFT = 'gift';

    public const DISCOUNT = 'discount';

    public const PROMOTIONAL = 'promotional';

    public const REFUND = 'refund';

    public const COMPENSATION = 'compensation';

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

    protected function casts(): array
    {
        return [
            'is_balance_based' => 'boolean',
            '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;
    }
}
