<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\Request;

class SettingController extends Controller
{
    public function index()
    {
        $settings = Setting::all()->pluck('value', 'key');
        return response()->json(['success' => true, 'data' => $settings]);
    }

    public function update(Request $request)
    {
        foreach ($request->all() as $key => $value) {
            Setting::set($key, $value);
        }
        return response()->json(['success' => true, 'message' => 'Settings saved']);
    }

    public function public()
    {
        $publicKeys = [
            'site_name', 'site_email', 'site_phone', 'site_address',
            'free_shipping_above', 'default_shipping',
            'instagram', 'facebook', 'twitter',
            'currency', 'currency_symbol',
            'payment_razorpay_enabled', 'razorpay_key_id',
            'payment_phonepe_enabled',
            'payment_cod_enabled',
        ];

        $settings = Setting::whereIn('key', $publicKeys)->get()->pluck('value', 'key');
        return response()->json(['success' => true, 'data' => $settings]);
    }
}
