<?php

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

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

class EmailController extends Controller
{
    private Config $configModel;

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

    /**
     * 이메일 양식
     * @method GET
     * @see /admin/config/form/email
     */
    public function index()
    {
        return view('admin.config.form.email', [
            'config' => $this->configModel
        ]);
    }

    /**
     * 이메일 양식 저장
     * @method POST
     * @see /admin/config/form/email
     */
    public function store(Request $request)
    {
        $rules = [
            'send_email_register_form_title' => 'string|nullable',
            'send_email_register_form_content' => 'string|nullable',
            'send_email_changepw_form_title' => 'string|nullable',
            'send_email_changepw_form_content' => 'string|nullable',
            'send_email_withdraw_form_title' => 'string|nullable',
            'send_email_withdraw_form_content' => 'string|nullable',
            /*
            'send_email_auth_form_title' => 'string|nullable',
            'send_email_auth_form_content' => 'string|nullable',
            'send_email_verify_code_form_title' => 'string|nullable',
            'send_email_verify_code_form_content' => 'string|nullable',
            */
            'send_email_find_form_title' => 'string|nullable',
            'send_email_find_form_content' => 'string|nullable',
            'send_email_post_form_title' => 'string|nullable',
            'send_email_post_form_content' => 'string|nullable',
            'send_email_comment_form_title' => 'string|nullable',
            'send_email_comment_form_content' => 'string|nullable',
            'send_email_post_blame_form_title' => 'string|nullable',
            'send_email_post_blame_form_content' => 'string|nullable',
            'send_email_comment_blame_form_title' => 'string|nullable',
            'send_email_comment_blame_form_content' => 'string|nullable',
            'send_email_post_personal_form_title' => 'string|nullable',
            'send_email_post_personal_form_content' => 'string|nullable',
            'send_email_post_personal_reply_form_title' => 'string|nullable',
            'send_email_post_personal_reply_form_content' => 'string|nullable'
        ];

        $attributes = [
            'send_email_register_form_title' => '회원가입 - 제목',
            'send_email_register_form_content' => '회원가입 - 내용',
            'send_email_changepw_form_title' => '비밀번호 변경 - 제목',
            'send_email_changepw_form_content' => '비밀번호 변경 - 내용',
            'send_email_withdraw_form_title' => '회원탈퇴 - 제목',
            'send_email_withdraw_form_content' => '회원탈퇴 - 내용',
            /*
            'send_email_auth_form_title' => '이메일 인증',
            'send_email_auth_form_content' => '이메일 인증',
            'send_email_verify_code_form_title' => '인증번호 - 제목',
            'send_email_verify_code_form_content' => '인증번호 - 내용',
            */
            'send_email_find_form_title' => '회원정보 찾기 - 제목',
            'send_email_find_form_content' => '회원정보 찾기 - 내용',
            'send_email_post_form_title' => '게시글 작성 - 제목',
            'send_email_post_form_content' => '게시글 작성 - 내용',
            'send_email_comment_form_title' => '댓글 작성 - 제목',
            'send_email_comment_form_content' => '댓글 작성 - 내용',
            'send_email_post_blame_form_title' => '게시글 신고 - 제목',
            'send_email_post_blame_form_content' => '게시글 신고 - 내용',
            'send_email_comment_blame_form_title' => '댓글 신고 - 제목',
            'send_email_comment_blame_form_content' => '댓글 신고 - 내용',
            'send_email_post_personal_form_title' => '1:1 문의 접수 - 제목',
            'send_email_post_personal_form_content' => '1:1 문의 접수 - 내용',
            'send_email_post_personal_reply_form_title' => '1:1 문의 답변 - 제목',
            'send_email_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.email.index')->with('message', $message);
    }

    /**
     * 이메일 레이아웃 보기
     * @method GET
     * @see /admin/config/form/email/layout
     */
    public function layout()
    {
        return view('component.email');
    }
}
