<?php

namespace App\Http\Controllers\Admin\Warehouse;

use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Product;
use App\Models\PurchaseMaster;
use App\Models\Units;
use App\Models\Warehouse;
use App\Service\Warehouse\WarehouseService;
use Illuminate\Http\Request;
use Inertia\Inertia;

class CheckerMakerController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        return Inertia::render('Warehouse/CheckMaker');
    }

    public function view()
    {
        $purchases = PurchaseMaster::where('status', 1)->with('PurchaseDetalis')->get();
        $product = Product::get();
        $unit = Units::get();
        $category = Category::get();
        $warehouse = Warehouse::get();

        return response()->json(['purchases' => $purchases, 'product' => $product, 'unit' => $unit, 'category' => $category, 'warehouse' => $warehouse]);
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        WarehouseService::PurchaseDataStore(request()->all(), $id);
        $purchases = PurchaseMaster::where('status', 1)->with('PurchaseDetalis')->get();

        return response()->json(['success' => 'Stock Update Successfully', 'purchases' => $purchases]);
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        //
    }
}
