<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     */
    protected $fillable = [
        'customer_id',
        'customer_name',
        'company_name',
        'designation',
        'email',
        'mobile_no',
        'address',
        'pincode',
        'date',
        'password',

        // newly added customer fields
        'status',          // active / inactive
        'customer_type',   // premium / regular
        'profile_image',   // optional image
    ];

    /**
     * Attributes that should be hidden.
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Attribute casting.
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }

    /**
     * Relationship: User → MarkList (Many)
     */
    public function marks()
    {
        return $this->hasMany(\App\Models\MarkList::class, 'customer_id', 'customer_id');
    }

    /**
     * Relationship: User → Orders (Through MarkList)
     */
    public function orders()
    {
        return $this->hasManyThrough(
            \App\Models\Order::class,
            \App\Models\MarkList::class,
            'customer_id',  // MarkList.customer_id
            'mark_no',      // Orders.mark_no
            'customer_id',  // Users.customer_id
            'mark_no'       // MarkList.mark_no
        );
    }

    /**
     * JWT Identifier
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * JWT Custom Claims
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
public function invoices()
{
    return $this->hasMany(\App\Models\Invoice::class, 'customer_id', 'id');
}



}
