<?php

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

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

class SmsController extends Controller
{
    private Config $configModel;

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

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

    /**
     * 문자 양식 저장
     * @method POST
     * @see /admin/config/form/sms
     */
    public function store(Request $request)
    {
        $rules = [
            'send_sms_register_form_content' => 'string|nullable',
            'send_sms_changepw_form_content' => 'string|nullable',
            'send_sms_withdraw_form_content' => 'string|nullable',
            'send_sms_auth_form_content' => 'string|nullable',
            'send_sms_find_form_content' => 'string|nullable',
            'send_sms_post_form_content' => 'string|nullable',
            'send_sms_comment_form_content' => 'string|nullable',
            'send_sms_post_blame_form_content' => 'string|nullable',
            'send_sms_comment_blame_form_content' => 'string|nullable',
            'send_sms_post_personal_form_content' => 'string|nullable',
            'send_sms_post_personal_reply_form_content' => 'string|nullable'
        ];

        $attributes = [
            'send_sms_register_form_content' => '회원가입',
            'send_sms_changepw_form_content' => '비밀번호 변경',
            'send_sms_withdraw_form_content' => '회원탈퇴',
            'send_sms_auth_form_content' => '이메일 인증',
            'send_sms_find_form_content' => '회원정보 찾기',
            'send_sms_post_form_content' => '게시글 작성',
            'send_sms_comment_form_content' => '댓글 작성',
            'send_sms_post_blame_form_content' => '게시글 신고',
            'send_sms_comment_blame_form_content' => '댓글 신고',
            'send_sms_post_personal_form_content' => '1:1 문의 접수 - 게시글',
            'send_sms_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.sms.index')->with('message', $message);
    }
}
