<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Commande extends Model
{
    protected $table      = 'commandes';
    protected $connection = 'default';

    protected $fillable = [
        'presta_order_id', 'presta_order_ref', 'user_id', 'produit_id',
        'chrono_id', 'atelier_id', 'statut', 'type_commande', 'is_b2b', 'is_test',
        'b2b_client_nom', 'b2b_quantite', 'texte_gravure', 'validation_sportif',
        'date_validation', 'numero_suivi', 'transporteur', 'date_expedition',
        'presta_synced', 'notes',
    ];

    public function user()    { return $this->belongsTo(User::class, 'user_id'); }
    public function produit() { return $this->belongsTo(Produit::class, 'produit_id'); }
    public function chrono()  { return $this->belongsTo(Chrono::class, 'chrono_id'); }
    public function atelier() { return $this->belongsTo(Atelier::class, 'atelier_id'); }
    public function lots()    { return $this->belongsToMany(Lot::class, 'commande_lot', 'commande_id', 'lot_id'); }
    public function savTickets(){ return $this->hasMany(SavTicket::class, 'commande_id'); }
}
