<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;

class RecepcionCompra extends Model
{
    protected $table = 'recepciones_compra';

    public $timestamps = false;

    protected $fillable = [
        'empresa_id',
        'orden_compra_id',
        'sucursal_id',
        'usuario_id',
        'numero_recepcion',
        'fecha_recepcion',
        'estado',
        'observacion',
    ];

    protected function casts(): array
    {
        return [
            'fecha_recepcion' => 'datetime',
            'created_at' => 'datetime',
        ];
    }

    public function sucursal(): BelongsTo
    {
        return $this->belongsTo(Sucursal::class, 'sucursal_id');
    }
    public function ordenCompra(): BelongsTo
    {
        return $this->belongsTo(OrdenCompra::class, 'orden_compra_id');
    }
    public function empresa(): BelongsTo
    {
        return $this->belongsTo(Empresa::class, 'empresa_id');
    }
    public function usuario(): BelongsTo
    {
        return $this->belongsTo(User::class, 'usuario_id');
    }

    public function detalles(): HasMany
    {
        return $this->hasMany(RecepcionCompraDetalle::class, 'recepcion_id');
    }
}
