<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Style;
use App\Settings\GeneralSettings;

class StyleController extends Controller
{
    public function __construct(private GeneralSettings $settings) {}

    public function index()
    {
        $styles = Style::with(['aiModel.primaryApiProvider'])
            ->where('enabled', true)
            ->whereHas('aiModel', function ($query) {
                $query->where('enabled', true);
                $query->whereHas('primaryApiProvider', function ($query) {
                    $query->where('enabled', true);
                });
            })
            ->get()
            ->sortBy('sort_order');

        if ($styles->isEmpty()) {
            return response()->json(['message' => __('api.no_styles_available')], 404);
        }

        return response()->json($styles);
    }

    public function getImageRefreshInterval()
    {
        return response()->json([
            'interval' => $this->settings->image_refresh_interval / 1000,
        ]);
    }

    public function getMaxNumberOfCopies()
    {
        return response()->json([
            'max_copies' => $this->settings->max_number_of_copies,
        ]);
    }
}
