<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Quality\PerformanceReportConfirmRequest;
use App\Http\Requests\Quality\PerformanceReportMemoRequest;
use App\Services\PerformanceReportService;
use Illuminate\Http\Request;

class PerformanceReportController extends Controller
{
    public function __construct(private PerformanceReportService $service) {}

    public function index(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->index($request->all());
        }, __('message.fetched'));
    }

    public function stats(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->stats($request->all());
        }, __('message.fetched'));
    }

    public function confirm(PerformanceReportConfirmRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->confirm($request->validated()['ids']);
        }, __('message.updated'));
    }

    public function unconfirm(PerformanceReportConfirmRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->unconfirm($request->validated()['ids']);
        }, __('message.updated'));
    }

    public function updateMemo(PerformanceReportMemoRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            $data = $request->validated();

            return $this->service->updateMemo($data['ids'], $data['memo']);
        }, __('message.updated'));
    }

    public function missing(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->missing($request->all());
        }, __('message.fetched'));
    }
}
