<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PointsTransaction extends Model
{
    protected $fillable = [
        'user_id',
        'type',
        'amount',
        'balance_after',
        'description',
        'visit_date',
        'spend_amount',
        'visit_id',
        'admin_id',
        'admin_note',
        'note_visible_to_member',
    ];

    protected function casts(): array
    {
        return [
            'visit_date'              => 'date',
            'spend_amount'            => 'decimal:2',
            'note_visible_to_member'  => 'boolean',
        ];
    }

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

    public function visit()
    {
        return $this->belongsTo(Visit::class);
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class);
    }

    public function isCredit(): bool
    {
        return $this->type === 'credit';
    }

    public function isDebit(): bool
    {
        return in_array($this->type, ['debit', 'expiry']);
    }
}
