<?php

namespace App\Models;

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

class ManyChatCarrito extends Model
{
    protected $table = 'manychat_carritos';

    protected $fillable = [
        'empresa_id',
        'session_id',
        'cliente_nombre',
        'telefono',
        'direccion',
        'observaciones',
        'total',
        'estado',
        'pedido_id',
        'last_activity_at',
        'confirmed_at',
    ];

    protected function casts(): array
    {
        return [
            'total' => 'decimal:2',
            'last_activity_at' => 'datetime',
            'confirmed_at' => 'datetime',
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ];
    }

    public function empresa(): BelongsTo
    {
        return $this->belongsTo(Empresa::class, 'empresa_id');
    }

    public function pedido(): BelongsTo
    {
        return $this->belongsTo(ManyChatPedido::class, 'pedido_id');
    }

    public function items(): HasMany
    {
        return $this->hasMany(ManyChatCarritoItem::class, 'carrito_id');
    }
}
