<?php

namespace App\Models;

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

class Session extends Model
{
    use HasFactory;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'ampeco_sessions'; // ¡Importante! Especificamos el nuevo nombre de la tabla

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'ampeco_session_id',
        'ampeco_user_id',
        'ampeco_charge_point_id',
        'started_at',
        'stopped_at',
        'amount',
        'energy',
        'location_name',
        'charger_name',
        'connector_name',
        'location_address_en',
        'payment_method_id',
        'payment_type',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'started_at' => 'datetime',
        'stopped_at' => 'datetime',
        'amount' => 'double',
        'energy' => 'double',
    ];

    // Si necesitas relaciones, las añadirías aquí más adelante
    /**
     * Get the Ampeco user that owns the session.
     */
    public function ampecoUser()
    {
        // Relacionamos con ampeco_user_id de la tabla ampeco_users
        return $this->belongsTo(AmpecoUser::class, 'ampeco_user_id', 'ampeco_user_id');
    }

    /**
     * Get the Ampeco charge point associated with the session.
     */
    public function chargePoint()
    {
        // Relacionamos con ampeco_charge_point_id de la tabla charge_points
        return $this->belongsTo(ChargePoint::class, 'ampeco_charge_point_id', 'ampeco_charge_point_id');
    }
}