<?php

namespace App\Models;

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

class AmpecoUser extends Model
{
    use HasFactory;

    protected $table = 'ampeco_users';

    protected $fillable = [
        'ampeco_user_id',
        'first_name',
        'last_name',
        'email',
        'phone',
        'group_ids_json',
        'partner_id',
        'group_id'
    ];

    protected $casts = [
        'ampeco_user_id' => 'integer',
        'group_ids_json' => 'array',
    ];

    public function sessions()
    {
        return $this->hasMany(Session::class, 'ampeco_user_id', 'ampeco_user_id');
    }

    public function partner()
    {
        return $this->belongsTo(Partner::class, 'partner_id', 'id');
    }

    public function group()
    {
        return $this->belongsTo(Group::class, 'group_id', 'id');
    }

    // Relación indirecta con usuarios a través del partner
    public function users()
    {
        return $this->hasMany(User::class, 'partner_id', 'partner_id');
    }
}