<?php

namespace App\Http\Controllers\Admin\Customer;

use App\Http\Controllers\Controller;
use App\Http\Requests\CustomerOpeningStock\CustomerOpeningStockStoreRequest;
use App\Http\Requests\CustomerOpeningStock\CustomerOpeningStockUpdateRequest;
use App\Models\CustomerOpening;
use App\Service\CustomerOpening\CustomerOpeningService;
use Inertia\Inertia;

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

    public function view()
    {
        return response()->json(['customers' => $this->getData()]);
    }

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

    public function getData()
    {
        return CustomerOpening::with('details', 'client', 'location')->get();

    
    }

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

        CustomerOpeningService::store(request()->all());

        return response()->json(['success' => 'Data insert Successfully', 'customers' => $this->getData()]);
    }

    /**
     * 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(CustomerOpeningStockUpdateRequest $customer, string $id)
    {
        CustomerOpeningService::update(request()->all(), $id);

        return response()->json(['success' => 'Data Update Successfully', 'customers' => $this->getData()]);
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        
        CustomerOpeningService::delete($id);

        return response()->json(['success' => 'Data Delete Successfully', 'customers' => $this->getData()]);
    }
}
