<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class modelRooms extends Model
{
   
    public static function selectrooms($code)
    {

        return DB::select("SELECT `ID`, `Code`, `Floor`, `Room`, `Space`, (select Name from tenants where tenants.TenantCode= Tenant limit 1) as `Tenant`,`Tenant` as TenantCode, `EntryDate` FROM `rooms`  where Code='$code' order by Room asc");

    }
    public static function selectTenant($code)
    {

        return DB::select("SELECT * FROM `tenants` where Code='$code' order by ID desc");

    }

    public static function selectfloors($code)
    {

        return DB::select("SELECT * FROM `floors` where Code='$code' order by FloorNumber asc");

    }
    public static function selectroomsName($code,$name)
    {

        return DB::select("SELECT * FROM `rooms` where Code='$code' and Room='$name'");
        
    }
    public static function saveRoom($code,$floor,$room, $space,$tenant)
    {
        return DB::insert("INSERT INTO `rooms` ( `Code`, `Floor`, `Room`, `Space`, `Tenant`) VALUES (?, ?,?, ?,?)", [$code,$floor,$room, $space,$tenant] );
    }
    public static function editRoom( $code,$id,$floor,$room, $space,$tenant)
    {
      
        return DB::update("UPDATE `rooms` SET  `Floor` = ?, `Room` = ?, `Space` = ?, `Tenant` = ? WHERE `ID` = ? and `Code` = ? ", [ $floor,$room, $space,$tenant, $id,$code]);
    }
    public static function deleterooms( $code,$id)
    {
        return DB::update("DELETE FROM `rooms`  WHERE `ID` = ? and `Code` = ? ", [$id,$code]);
    }
}
