<?php

namespace App\Models\Finance;

use App\Models\Crm\Customer;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class CustomerAccount extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'customer_id', 'cash_balance', 'card_balance', 'points',
    ];

    protected function casts(): array
    {
        return [
            'cash_balance' => 'decimal:2',
            'card_balance' => 'decimal:2',
            'points' => 'integer',
        ];
    }

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

    public function transactions(): HasMany
    {
        return $this->hasMany(AccountTransaction::class, 'customer_account_id');
    }
}
