<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CustomerLedger extends Model
{
    use HasUlids, SoftDeletes;

    protected $table = 'customer_ledger';

    protected $fillable = [
        'user_id', 'store_id', 'local_id', 'customer_id', 'type', 'amount',
        'balance', 'reference_type', 'reference_id', 'notes', 'entry_date',
        'device_id', 'sync_version', 'is_deleted',
    ];

    protected $casts = [
        'amount' => 'float',
        'balance' => 'float',
        'is_deleted' => 'boolean',
        'sync_version' => 'integer',
        'entry_date' => 'datetime',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class, 'customer_id');
    }
}
