<?php

namespace App\Models;

use CodeIgniter\Model;

class PlanChangeRequestModel extends Model
{
    protected $table         = 'plan_change_requests';
    protected $useTimestamps = false;
    protected $allowedFields = [
        'agency_id', 'requested_by_user_id', 'current_plan_id', 'requested_plan_id',
        'billing_cycle', 'status', 'note', 'reviewed_by_user_id', 'reviewed_at', 'created_at',
    ];

    public function pendingFor(int $agencyId): ?array
    {
        return $this->where('agency_id', $agencyId)->where('status', 'pending')->orderBy('created_at', 'DESC')->first();
    }
}
