<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

use App\Models\Payer;
use Illuminate\Support\Facades\DB;

class PayerController extends Controller
{
	public function searchPayerV2JSON(Request $request)
	{
		$term = $request->input('term') ? trim($request->input('term')) : '';
		if (empty($term)) return '';
		$matches = DB::select(
			"
			SELECT id, uid, (name || ' (' || COALESCE(availity_payer_id, '--') || ')') as text FROM payer WHERE name ILIKE :term OR memo ILIKE :term", 
			['term' => '%' . $term . '%']
		);

		return json_encode([
			"success" => true,
			"data" => $matches
		]);
	}
}
