<?php

namespace App\Http\Controllers;

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

use Illuminate\Http\Request;
use App\Models\FindAClinicRequest;
use App\Models\ContactMessage;

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 findAClinic() {
      return view('app.find-a-clinic');
    }
    public function submitFindAClinic(Request $request) {
      $request->validate([
        'name_first' => 'required|string',
        'name_last' => 'required|string',
        'email' => 'required|email',
        'phone' => 'required|string',
        'zip' => 'required|string'
      ]);
      
      $record = new FindAClinicRequest;
      $record->iid = $this->makeIID();
      $record->uid = Uuid::uuid6();
      $record->name_first = $request->get('name_first');
      $record->name_last = $request->get('name_last');
      $record->email = $request->get('email');
      $record->phone = $request->get('phone');
      $record->zip = $request->get('zip');

      $record->save();
      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'
      ]);
      
      $record = new ContactMessage;
      $record->iid = $this->makeIID();
      $record->uid = Uuid::uuid6();
      $record->name_first = $request->get('name_first');
      $record->name_last = $request->get('name_last');
      $record->email = $request->get('email');
      $record->phone = $request->get('phone');
      $record->zip = $request->get('zip');
      $record->subject = $request->get('subject');
      $record->message = $request->get('message');

      $record->save();
      return redirect()->back()->with('success', 'Your request has been submitted!');
    }
}
