<?php

namespace App\Http\Controllers;

use App\Services\BoardService;
use Illuminate\View\View;

class BoardController extends Controller
{
    public function __construct(
        private readonly BoardService $boardService
    ) {}

    /**
     * 게시판 목록 (Blade 화면)
     */
    public function index(): View
    {
        $boardTypes = $this->boardService->getBoardTypes();
        $currentTenant = auth()->user()->currentTenant();

        return view('boards.index', compact('boardTypes', 'currentTenant'));
    }

    /**
     * 게시판 생성 화면
     */
    public function create(): View
    {
        return view('boards.create');
    }

    /**
     * 게시판 수정 화면
     */
    public function edit(int $id): View
    {
        // systemOnly=false: 테넌트 게시판도 수정 가능
        $board = $this->boardService->getBoardById($id, true, false);

        if (! $board) {
            abort(404, '게시판을 찾을 수 없습니다.');
        }

        return view('boards.edit', compact('board'));
    }
}
