<?php

namespace App\Http\Controllers;

use App\Http\Traits\StringGeneratorTrait;
use Ramsey\Uuid\Uuid;

use Illuminate\Http\Request;
use App\Models\PatientFindAClinicRequest;
use App\Models\PatientContactMessage;

class AppController extends Controller
{
  use StringGeneratorTrait;

    public function index() {
      return view('app.index');
    }
    public function snyderhemband() {
      return view('app.snyder');
    }
    public function aboutHem() {
      return view('app.about-hem');
    }
    public function treatment() {
      return view('app.treatment');
    }
    public function postCare() {
      return view('app.post-care');
    }
    public function compare() {
      return view('app.compare');
    }
    public function contact() {
      return view('app.contact');
    }
    public function faqs() {
      return view('app.faqs');
    }
    public function privacy() {
      return view('app.privacy');
    }
    public function terms() {
      return view('app.terms');
    }
    public function giSurveyQuestions(Request $request){
      return view('app.gi-survey-questions');
    }
    public function findAClinic() {
      return view('app.find-a-clinic');
    }

    public function submitGiSurveyQuestions(Request $request){
      $request->validate([
        'first_name' => 'required|string',
        'last_name' => 'required|string',
        'phone_number' => 'required|string',
        'email' => 'required|email',
        'g-recaptcha-response' => 'required|recaptcha'
      ]);

      $request['form_name'] = 'survey';
      $this->saveWebForm($request);

      $this->sendWebsiteEmailNotification([
        'template' => 'generic',
        'subject' => 'Survey Questions',
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('success', 'Your request has been submitted!');

    }
    public function submitFindAClinic(Request $request) {
      $request->validate([
        'name_first' => 'required|string',
        'name_last' => 'required|string',
        'email' => 'required|email',
        'phone' => 'required|string',
        'zip' => 'required|string',
        'g-recaptcha-response' => 'required|recaptcha'
      ]);

      $request['form_name'] = 'patient_find_a_clinic';
      $this->saveWebForm($request);

      $this->sendWebsiteEmailNotification([
        'template' => 'find-a-clinic',
        'subject' => 'Find a clinic request',
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('success', 'Your request has been submitted!');
    }

    public function submitContact(Request $request) {
      $request->validate([
        'name_first' => 'required|string',
        'name_last' => 'required|string',
        'email' => 'required|email',
        'phone' => '',
        'zip' => '',
        'subject' => '',
        'message' => 'required|string',
        'g-recaptcha-response' => 'required|recaptcha'
      ]);

      $request['form_name'] = 'patient_contact_message';
      $this->saveWebForm($request);

      $this->sendWebsiteEmailNotification([
        'template' => 'contact',
        'subject' => $request->get('subject'),
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('success', 'Your request has been submitted!');
    }
}
