<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Http\Requests\VersionRequest;
use App\Models\Version;
use App\Traits\BaseApiResponse;

class VersionController extends Controller
{
    use BaseApiResponse;

    public function index(VersionRequest $versionRequest)
    {
        $version = Version::query()->where('type', $versionRequest->type)->orderBy('id', 'desc')->first();

        if (!$version) {
            return $this->failed([], 'Version not found');
        }

        if (intval($version->number) > $versionRequest->number) {
            return $this->success([
                'force_update' => $version->force_update == 1 ? true : false
            ], 'Your app need to be updated');
        }

        return $this->success([
            'force_update' => false
        ], 'Version successfully');
    }
}
