<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Tenant\TenantLogoUploadRequest;
use App\Http\Requests\Tenant\TenantStoreRequest;
use App\Http\Requests\Tenant\TenantUpdateRequest;
use App\Services\TenantService;
use Illuminate\Http\Request;

class TenantController extends Controller
{
    public function __construct(private TenantService $service) {}

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

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

    public function store(TenantStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->storeTenants($request->validated());
        }, __('message.tenant.created'));
    }

    public function update(TenantUpdateRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->updateTenant($request->validated());
        }, __('message.tenant.updated'));
    }

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

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

    public function uploadLogo(TenantLogoUploadRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->uploadLogo($request->file('logo'));
        }, __('message.tenant.logo_uploaded'));
    }
}
