<?php

namespace App\Models;

use App\Models\Concerns\BelongsToBusiness;
use App\Models\Concerns\WritesAuditLog;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Member extends Model
{
    use BelongsToBusiness, HasUuids, SoftDeletes, WritesAuditLog;

    protected $fillable = ['member_number', 'full_name', 'photo_path', 'phone', 'whatsapp', 'email', 'gender', 'address', 'next_of_kin', 'notes', 'is_active'];

    protected function casts(): array
    {
        return ['next_of_kin' => 'array', 'is_active' => 'boolean'];
    }

    public function groups(): BelongsToMany
    {
        return $this->belongsToMany(AjoGroup::class, 'group_members')->withPivot(['payout_position', 'joined_at', 'status'])->withTimestamps();
    }

    public function contributions(): HasMany
    {
        return $this->hasMany(Contribution::class);
    }

    public function payouts(): HasMany
    {
        return $this->hasMany(Payout::class);
    }
}
