<?php

namespace App\Http\Controllers\API\V1\Admin;

use App\Http\Controllers\Controller;
use App\Models\Asset;
use Illuminate\Http\Request;

class AssetManagementController extends Controller
{
    public function index()
    {
        return response()->json(['success' => true, 'data' => Asset::all()]);
    }

    public function store(Request $request)
    {
        $asset = Asset::create($request->all());
        return response()->json(['success' => true, 'data' => $asset], 201);
    }

    public function show(int $id)
    {
        return response()->json(['success' => true, 'data' => Asset::findOrFail($id)]);
    }

    public function update(Request $request, int $id)
    {
        $asset = Asset::findOrFail($id);
        $asset->update($request->all());
        return response()->json(['success' => true, 'data' => $asset]);
    }

    public function destroy(int $id)
    {
        Asset::findOrFail($id)->delete();
        return response()->json(['success' => true, 'message' => 'Asset deleted']);
    }

    public function toggleStatus(int $id)
    {
        $asset = Asset::findOrFail($id);
        $asset->update(['is_active' => !$asset->is_active]);
        return response()->json(['success' => true, 'data' => $asset]);
    }
}
