<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system;

use plugin\saiadmin\app\logic\system\SystemAdminGuideLogic;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;

/**
 * 后台操作指南控制器
 */
class SystemAdminGuideController extends BaseController
{
    private SystemAdminGuideLogic $guideLogic;

    public function __construct()
    {
        $this->guideLogic = new SystemAdminGuideLogic();
        parent::__construct();
    }

    /**
     * 读取后台操作指南 Markdown 内容
     */
    #[Permission('后台操作指南读取', 'system:admin_guide:index:read')]
    public function read(Request $request): Response
    {
        $data = $this->guideLogic->read();
        return $this->success($data);
    }

    /**
     * 保存后台操作指南 Markdown 内容
     */
    #[Permission('后台操作指南保存', 'system:admin_guide:index:save')]
    public function save(Request $request): Response
    {
        $content = $request->post('content', '');
        if (! is_string($content)) {
            return $this->fail('invalid content');
        }
        $data = $this->guideLogic->save($content);
        return $this->success($data, 'save success');
    }
}
