<?php

namespace App\Http\Controllers;

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

use Illuminate\Http\Request;

use App\Models\PhysicianTrainingRequest;
use App\Models\PhysicianContactMessage;
use App\Models\PhysicianDirectoryListingRequest;
use App\Models\PhysicianMarketingMaterialsRequest;
use App\Models\LigatorOrder;

class PhysiciansController extends Controller
{

  use StringGeneratorTrait;

    public function index(Request $request) {
      return view('app.hcp.index');
    }

    public function instructionsForUse(Request $request){
      return view('app.hcp.instructions-for-use');
    }
    public function practiceSupport(Request $request){
      return view('app.hcp.practice-support');
    }
    public function practiceSupportReimbursement(Request $request){
      return view('app.hcp.practice-support.reimbursement');
    }
    public function practiceSupportTraining(Request $request){
      return view('app.hcp.practice-support.training');
    }
    public function practiceSupportDirectoryListing(Request $request){
      return view('app.hcp.practice-support.directory-listing');
    }
    public function orderProducts(Request $request){
      return view('app.hcp.order-products');
    }
    public function orderProductsLigators(Request $request){
      return view('app.hcp.order-products.ligators');
    }
    public function orderProductsSamples(Request $request){
      return view('app.hcp.order-products.samples');
    }
    public function orderProductsMarketing(Request $request){
      return view('app.hcp.order-products.marketing');
    }
    public function orderProductsObp(Request $request){
      return view('app.hcp.order-products.obp');
    }
    public function fdaRegistration(Request $request){
      return view('app.hcp.fda-registration');
    }
    public function contactUs(Request $request){
      return view('app.hcp.contact-us');
    }
    public function getTrained(Request $request){
      return view('app.hcp.get-trained');
    }
    public function reimbursementGuide(Request $request){
      return view('app.hcp.reimbursement-guide');
    }
    public function privacy() {
      return view('app.privacy');
    }
    public function terms() {
      return view('app.terms');
    }

    public function termsOfSale() {
        return view('app.terms-of-sale');
    }

    public function suctionEssentials() {
        return view('app.suction-essentials');
    }

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

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

      $this->sendWebsiteEmailNotification([
        'template' => 'training-request',
        'subject' => 'Hemband Training Request',
        'data' => (object) $request->all()
      ]);

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

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

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

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

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

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

      $this->sendWebsiteEmailNotification([
        'template' => 'physician-directory-listing-request',
        'subject' => 'Hemband Physician Directory Listing Request Form',
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('success', 'Your request has been submitted!');
    }
    public function submitOrderProductsMarketing(Request $request) {
      $request->validate([
        'name_first' => 'required|string',
        'name_last' => 'required|string',
        'title' => 'required|string',
        'practice_name' => 'required|string',
        'practice_address' => 'required|string',
        'email' => 'required|email',
        'phone' => 'required|string',
        'zip' => 'required|string',
        'comment' => 'required|string',
        'g-recaptcha-response' => 'required|recaptcha'
      ]);

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

      $this->sendWebsiteEmailNotification([
        'template' => 'physician-marketing-materials-request',
        'subject' => 'Hemband Physician Marketing Materials Request Form',
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('success', 'Your request has been submitted!');
    }
    public function submitRequestSamples(Request $request){
      $request->validate([
        'company_name' => 'required|string',
        'order_phyisician_name' => 'required|string',
        'phone_number' => 'required|string',
        'purchasing_contact_name' => 'required|string',
        'email' => 'required|email',
        'state' => 'required|string',
        'city' => 'required|string',
        'zip' => 'required|string',
        'shipping_address' => 'required|string',
        'g-recaptcha-response' => 'required|recaptcha'
      ]);

      $request['form_name'] = 'physician_request_sample';
      $record = $this->saveWebForm($request);
      //
      $this->sendWebsiteEmailNotification([
        'template' => 'physician-request-sample',
        'subject' => 'Physician Request Sample',
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('orderIID', $record->iid)->with('success', 'Your sample has been submitted!');
    }
    public function submitOrderLigators(Request $request){
      $request->validate([
        'order_date' => 'required|string',
        'company_name' => 'required|string',
        'order_phyisician_name' => 'required|string',
        'phone_number' => 'required|string',
        'purchasing_contact_name' => 'required|string',
        'email' => 'required|email',
        'state' => 'required|string',
        'city' => 'required|string',
        'zip' => 'required|string',
        'shipping_address' => 'required|string',
        'g-recaptcha-response' => 'required|recaptcha'
      ]);

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

      $this->sendWebsiteEmailNotification([
        'template' => 'physician-order-ligators',
        'subject' => 'Physician Ligator Order',
        'data' => (object) $request->all()
      ]);
      return redirect()->back()->with('orderIID', $record->iid)->with('success', 'Your order has been submitted!');
    }
}
