<?php

namespace App\Models\Lookups;

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

class PaymentTerm extends Model
{
    use BelongsToTenant;

    public const COD = 'cod';

    public const NET7 = 'net7';

    public const NET15 = 'net15';

    public const NET30 = 'net30';

    public const NET60 = 'net60';

    public const NET90 = 'net90';

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

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

    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;
    }
}
