<?php

namespace App\Http\Controllers;

use App\Models\CompanyProfile;
use App\Models\TrialCompanyProfile;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class TrialCompanyProfileController extends Controller
{
    public function index()
    {
        $authUser = auth()->guard('trial-account')->user();
        $companyProfile = TrialCompanyProfile::where('id', $authUser->id)->first();
        return view('pages.trial-account.company-profile')->with(compact(
            'companyProfile'
        ));
    }

    public function update(Request $request)
    {

        $request->validate([
            'contact_name' => 'required',
            'contact_number' => 'required',
            'email' => 'required',
            'roc' => 'required',
            'address_1' => 'required',
            'state' => 'required',
            'postcode' => 'required',
        ]);

        $address_2 = $request->address_2 ?? '';
        $address_3 = $request->address_3 ?? '';
        $address_4 = $request->address_4 ?? '';

        $profile = Auth::guard('trial-account')->user();
        $profile->update([
            'contact_name' => $request->contact_name,
            'contact_number' => $request->contact_number,
            'email' => $request->email,
            'roc' => $request->roc,
            'address1' => $request->address_1,
            'address2' => $address_2,
            'address3' => $address_3,
            'address4' => $address_4,
            'state' => $request->state,
            'postcode' => $request->postcode,
        ]);

        return redirect()->route('trial-accounts.dashboard');


    }
}
