<?php

namespace App\Http\Controllers\Share;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Core\Auth;
use App\Services\Share\LockService;
use Illuminate\Http\Request;

class LockController extends Controller
{
    public function succlist(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page') ?? 1;
        $pages = array(
            'limit' => 20,
            'page' => $page
        );
        $ls = new LockService();
        $data = $ls->succlist($uid, $pages);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    public function faillist(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page') ?? 1;
        $pages = array(
            'limit' => 20,
            'page' => $page
        );
        $ls = new LockService();
        $data = $ls->faillist($uid, $pages);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 创建解锁卡片分享链接
     * @param  int  $partner_id
     * @return array
     * @throws \App\Exceptions\AlertException
     * @throws \App\Exceptions\DBException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function store(int $partner_id)
    {
        $uid = Auth::auth();
        $ls = new LockService();
        $data = $ls->store($uid, $partner_id);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => [
                'list_id' => $data['id']
            ]
        );
    }
}
