<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Grievance extends Model
{
    protected $fillable = [
        'component',
        'sn',
        'complainant_name',
        'gender',
        'state_aa',
        'county',
        'payam',
        'project_beneficiary',
        'direct_type',
        'indirect_type',
        'report_date',
        'grievance_type',
        'case_category',
        'evidence_provided',
        'complaint_channel',
        'grm_actions_investigation',
        'grm_actions_resolved_closed',
        'grm_actions_no_actions',
        'grm_actions_date',
        'notification_decisions_outcome',
        'notification_follow_up_meetings',
        'notification_reported_mgcsw',
        'notification_reported_ttl',
        'notification_date',
        'grm_focal_person_name',
        'status',
        'group_id',
        'member_id',
        'beneficiary_id',
    ];

    protected $casts = [
        'report_date' => 'date',
        'grm_actions_date' => 'date',
        'notification_date' => 'date',
    ];

    // Relationships (for Component 1 integration)
    public function group() { return $this->belongsTo(C1Group::class); }
    public function member() { return $this->belongsTo(C1Member::class); }
    public function beneficiary() { return $this->belongsTo(C1WeofBeneficiary::class); }

    // Scope for component filtering
    public function scopeForComponent($query, $component) {
        return $query->where('component', $component);
    }
}
