<?php

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

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

class NoteController extends Controller
{
    private Config $configModel;

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

    /**
     * 쪽지 양식
     * @method GET
     * @see /admin/config/form/note
     */
    public function index()
    {
        return view('admin.config.form.note', []);
    }

    /**
     * 쪽지 양식 저장
     * @method POST
     * @see /admin/config/form/note
     */
    public function store(Request $request)
    {
        $rules = [
            'send_note_register_form_content' => 'string|nullable',
            'send_note_changepw_form_content' => 'string|nullable',
            'send_note_withdraw_form_content' => 'string|nullable',
            'send_note_auth_form_content' => 'string|nullable',
            'send_note_find_form_content' => 'string|nullable',
            'send_note_post_form_content' => 'string|nullable',
            'send_note_comment_form_content' => 'string|nullable',
            'send_note_post_blame_form_content' => 'string|nullable',
            'send_note_comment_blame_form_content' => 'string|nullable',
            'send_note_post_personal_form_content' => 'string|nullable',
            'send_note_post_personal_reply_form_content' => 'string|nullable'
        ];

        $attributes = [
            'send_note_register_form_content' => '회원가입',
            'send_note_changepw_form_content' => '비밀번호 변경',
            'send_note_withdraw_form_content' => '회원탈퇴',
            'send_note_auth_form_content' => '이메일 인증',
            'send_note_find_form_content' => '회원정보 찾기',
            'send_note_post_form_content' => '게시글 작성',
            'send_note_comment_form_content' => '댓글 작성',
            'send_note_post_blame_form_content' => '게시글 신고',
            'send_note_comment_blame_form_content' => '댓글 신고',
            'send_note_post_personal_form_content' => '1:1 문의 접수',
            'send_note_post_personal_reply_form_content' => '1:1 문의 답변'
        ];

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

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

        $message = '쪽지 양식 정보가 저장되었습니다.';
        return redirect()->route('admin.config.form.note.index')->with('message', $message);
    }
}
