<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class TreasuryInstrument extends Model
{
    use HasFactory;

    protected $fillable = [
        'code',
        'name',
        'instrument_type',
        'issuer',
        'face_value',
        'coupon_rate',
        'discount_rate',
        'issue_date',
        'maturity_date',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'face_value' => 'decimal:2',
            'coupon_rate' => 'decimal:4',
            'discount_rate' => 'decimal:4',
            'issue_date' => 'date',
            'maturity_date' => 'date',
        ];
    }

    public function positions(): HasMany
    {
        return $this->hasMany(TreasuryPosition::class, 'instrument_id');
    }
}
