<?php

namespace App\Http\Controllers\Api\InventoryCollection;

use App\Http\Controllers\Controller;
use App\Http\Requests\DisplayRequest;
use App\Http\Requests\MiscIssue\MiscIssueRequest;
use App\Http\Resources\MiscIssueResource;
use App\Services\MiscIssueService;
use Essa\APIToolKit\Api\ApiResponse;
use Illuminate\Http\Request;

class MiscIssueController extends Controller
{
    use ApiResponse;

    protected MiscIssueService $service;

    public function __construct(MiscIssueService $service)
    {
        $this->service = $service;
    }

    public function index(DisplayRequest $request)
    {
        $misc_issue = $this->service->getAll();

        if ($misc_issue->isEmpty()) {
            return $this->responseNotFound(
                __(
                    "messages.not_found",
                    ["module" => __("models.misc_issue_plural")]
                )
            );
        }

        $pagination = $request->pagination;

        if (!$pagination) {
            MiscIssueResource::collection($misc_issue);
        } else {
            $misc_issue = MiscIssueResource::collection($misc_issue);
        }

        return $this->responseSuccess(
            __(
                "messages.display",
                ["module" => __("models.misc_receipt_plural")]
            ),
            $misc_issue
        );
    }

    public function show($id)
    {
        $misc_issue = $this->service->getById($id);

        if (!$misc_issue) {
            return $this->responseNotFound(
                __(
                    "messages.not_found",
                    ["module" => __("models.misc_issue")]
                )
            );
        }

        return $this->responseSuccess(
            __(
                "messages.display",
                ["module" => __("models.misc_issue")]
            ),
            $misc_issue
        );
    }

    public function store(MiscIssueRequest $request)
    {
        $miscIssue = $this->service->create($request->all());

        return $this->responseCreated(
            __("messages.created", ["module" => __("models.misc_issue")]),
            $miscIssue
        );
    }

    public function update() {}
}
