<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ShareholderTransaction extends Model
{
    protected $fillable = [
        'shareholder_id', 'transaction_date', 'type', 'amount', 'notes',
    ];

    protected $casts = [
        'transaction_date' => 'date',
    ];

    public function shareholder()
    {
        return $this->belongsTo(Shareholder::class);
    }

    public function getTypeLabelAttribute(): string
    {
        return match($this->type) {
            'investment'        => 'Investment',
            'withdrawal'        => 'Withdrawal',
            'profit'            => 'Profit',
            'profit_withdrawal' => 'Profit Withdrawal',
            default             => ucfirst($this->type),
        };
    }

    public function getTypeBadgeAttribute(): string
    {
        return match($this->type) {
            'investment'        => 'success',
            'withdrawal'        => 'danger',
            'profit'            => 'primary',
            'profit_withdrawal' => 'warning',
            default             => 'secondary',
        };
    }
}
