<?php

declare(strict_types=1);

namespace App\Models\Market;

use App\Models\Model;
use App\Models\User;

class CooperativeMember extends Model
{
    protected ?string $table = 'cooperative_members';

    protected array $fillable = [
        'hashkey', 'organization_id', 'user_id', 'role',
        'membership_type', 'membership_level',
        'officer_position', 'officer_level',
        'concurrent_position', 'concurrent_level',
        'cooperative_name_alt', 'cooperative_position', 'year_beginning',
        // Classification
        'priority_sector', 'common_bond', 'vulnerability_classifications',
        // Government IDs
        'philsys_id', 'sss_number', 'pagibig_number',
        // SLP
        'slp_track', 'slp_association_name', 'listahanan_id', 'fourtps_household_id',
        // TUPAD
        'tupad_category', 'tupad_insurance_beneficiary_name', 'tupad_insurance_beneficiary_relation',
        // OSEC/NSRP
        'preferred_occupation', 'nsrp_skills', 'employment_status',
        // Programs
        'program_participation',
        'joined_at', 'is_active', 'created_by', 'updated_by',
    ];

    protected array $casts = [
        'joined_at'                   => 'datetime',
        'is_active'                   => 'boolean',
        'priority_sector'               => 'array',
        'vulnerability_classifications' => 'array',
        'nsrp_skills'                 => 'array',
        'program_participation'       => 'array',
    ];

    public function organization()
    {
        return $this->belongsTo(Organization::class, 'organization_id');
    }

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

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updater()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
