<?php

namespace App\Http\Controllers\Admin\Config\Register;

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

class ModifyController extends Controller
{
    private Config $configModel;

    public function __construct(Config $config)
    {
        $this->configModel = $config;
    }

    /**
     * 정보 수정시
     * @method GET
     * @see /admin/config/register/modify
     */
    public function index()
    {
        return view('admin.config.register.modify', []);
    }

    /**
     * 정보 수정시 저장
     * @method POST
     * @see /admin/config/register/modify
     */
    public function store(Request $request)
    {
        $rules = [
            'change_nickname_day' => 'required|numeric|min:0|max:365',
            'change_email_day' => 'required|numeric|min:0|max:365'
        ];

        $attributes = [
            'change_nickname_day' => '이름',
            'change_email_day' => 'E-mail'
        ];

        $posts = $this->validate($request, $rules, [], $attributes);

        $this->configModel->save($posts, $attributes);

        $message = '정보 수정시 정보가 저장되었습니다.';
        return redirect()->route('admin.config.register.modify.index')->with('message', $message);
    }
}
