<?php

class ACMS_POST_Entry_Lock_Exec extends ACMS_POST_Entry
{
    public function post()
    {
        $eid = intval($this->Post->get('eid'));
        $rvid = intval($this->Post->get('rvid', 0));
        /** @var int|null $sessionUserId */
        $sessionUserId = SUID;
        if ($sessionUserId === null) {
            Response::json([
                'locked' => false,
                'message' => 'ログインしていません',
            ]);
        }

        try {
            $service = App::make('entry.lock');
            assert($service instanceof \Acms\Services\Entry\Lock);
            $service->lock($eid, $rvid, $sessionUserId);

            Response::json([
                'locked' => true,
            ]);
        } catch (Exception $e) {
            Response::json([
                'locked' => false,
                'message' => $e->getMessage(),
            ]);
        }
    }
}
