<?php

namespace App\Http\Controllers;

use App\Models\Applience;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;


class RequestController extends Controller
{
    public function show() : View 
    {
        return view('request.request');
    }

    public function load()
    {
        $appliences = Applience::all();

        return $this->generateResponse('Success', '', $appliences);
    }

    public function reject($applience_id) 
    {
        $applience = Applience::find($applience_id);
        $applience->status = Applience::STATUS_REJECTED;
        $applience->save();

        return $this->generateResponse('Success', '', []);
    }

    public function process($applience_id) 
    {
        $applience = Applience::find($applience_id);
        $applience->status = Applience::STATUS_WORKING;
        $applience->save();

        return $this->generateResponse('Success', '', []);
    }

    public function assingDepartment($applience_id, Request $request) 
    {
        $applience = Applience::find($applience_id);
        $applience->department_id = $request->input('department');
        $applience->save();

        return $this->generateResponse('Success', '', []);
    }
}
