<?php

namespace App\Models;

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

class ReceiptRow extends Model
{
    use HasFactory;

    protected $table = 'receipts_rows';

    protected $fillable = [
        'receip_id',
        'causal_id',
        'course_id',
        'when',
        'amount',
        'note',
        'commercial',
        'aliquota_iva',
        'imponibile',
        'imposta',
        'divisa',
        'numero_linea',
        'prezzo_unitario',
        'quantita',
        'prediscount_amount',
        'sconto',
        'subscription_id',
    ];

    protected $casts = [
        'when' => 'json',
        'aliquota_iva' => 'decimal:2',
        'imponibile' => 'decimal:2',
        'imposta' => 'decimal:2',
        'prezzo_unitario' => 'decimal:2',
        'quantita' => 'decimal:2',
    ];

    public function causal()
    {
        return $this->belongsTo(Causal::class);
    }

    public function receipt()
    {
        return $this->belongsTo(Receipt::class, 'receip_id', 'id');
    }

    public function course()
    {
        return $this->belongsTo(Course::class);
    }

    public function subscription()
    {
        return $this->belongsTo(Subscription::class, 'subscription_id');
    }
}
