<?php

namespace App\Http\Controllers\Support;

use App\Http\Controllers\Controller;

use App\Models\Environment\PaymentMethod;
use App\Models\Environment\Business;

use App\Models\Hotel\Reservation;
use App\Models\Hotel\Status;
use App\Models\Hotel\Room;
use App\Models\Hotel\Agency;
use App\Models\Hotel\Source;
use App\Models\Hotel\Regimen;
use App\Models\Hotel\RoomType;

use App\Http\Controllers\Hotel\ReservationController;

use \App\Helpers\Environment\SystemFeaturesHelper;

class HomeController extends Controller
{
  //* Constructor
    public function __construct() {
        $this->middleware('auth');
    }

  //* Special Fucntions
    public function index() {
      //- General Controls
        $has_only_invoicing_system = SystemFeaturesHelper::getFeatureStatus('only_invoicing_system');

      //- Define Home Render
        if ($has_only_invoicing_system) { // Invoicing Home
            $establishment = Business::first();
            return view('home.invoicing-index', compact('establishment'));
        } else {
          // View Data
            $support_data = [
                'statuses' => Status::all(),
                'agencies' => Agency::all(),
                'sources' => Source::all(),
                'roomTypes' => RoomType::orderBy('id', 'desc')->get(),
                'rooms' => Room::all(),
                'regimens' => Regimen::all(),
                'paymentMethods' => PaymentMethod::all(),
            ];

            return view('home.index', [...$support_data]);
        }
    }

    // No show Interactions
    public function noShow($id, $type) {
      // Get record to update
        $data = Reservation::findOrFail($id);

      // Update Data
        $data->guest_status_id = 5;
            if ($data->is_express) $data->status_id = 7; // Express management
            if ($type) $data->show_in_calendar = 0; // No Show Type (Primary, Secondary, Tertiary)

        $data->save();

      // Update History
        (new ReservationController)->updateHistory($id, 'Update', auth()->user()->name);

      // Return response
        return response()->json([
            'success' => true,
            'message' => __('common_responses_and_messages')['updated_successfully']
        ]);
    }

}
