<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

/**
 * One graduated step of a TaxTable. `width` is the slice of taxable income the
 * `rate` applies to; a NULL width marks the open-ended top band.
 */
class TaxBand extends Model implements AuditableContract
{
    use Auditable;

    protected $fillable = [
        'tax_table_id',
        'sort',
        'width',
        'rate',
    ];

    protected function casts(): array
    {
        return [
            'sort' => 'integer',
            'width' => 'decimal:2',
            'rate' => 'decimal:4',
        ];
    }

    public function taxTable(): BelongsTo
    {
        return $this->belongsTo(TaxTable::class);
    }
}
