<?php

namespace App\Models;

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

class ClientReward extends BaseModel
{
    use HasFactory;

    protected $guarded = [];

    public function client()
    {
        return $this->belongsTo(Client::class, 'client_id');
    }

    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class, 'warehouse_id');
    }

    public function history()
    {
        return $this->hasMany(ClientRewardHistory::class, 'client_id', 'client_id')
            ->where('warehouse_id', $this->warehouse_id)
            ->orderBy('payment_date', 'desc');
    }
}
