<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\BillingAccount;

class BillingController extends Controller
{
    public function checkEmail(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
        ]);

        $billing = BillingAccount::where('invoice_email', $request->email)->first();

        if ($billing) {
            return response()->json([
                'exists' => true,
                'billing_account_id' => $billing->id,
                'billing_name' => $billing->name,
                'primary_parent_user_id' => $billing->primary_parent_user_id,
            ]);
        }

        return response()->json([
            'exists' => false,
        ]);
    }
}
