<?php

namespace App\Models;

use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Factura extends Model {
    use UuidPrimaryKey, SoftDeletes;

    protected $table = 'facturas';
    protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot'];
    protected $fillable = ['id', 'numero', 'monto_bruto', 'compra_id'];

    public static function findOrFail($id) {
        $factura = Factura::find($id);
        if(!$factura) throw new ModelNotFoundException("factura", $id);
        return $factura;
    }

    public function compra() {
        return $this->belongsTo(Compra::class);
    }
}
