<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace App\Http\Controllers\Admin\System;

use Illuminate\Http\Request;
use App\Http\Controllers\BaseController;
use App\Services\System\TasksService;

class Tasks extends BaseController {

	/**
	 * @title 任务列表
	 *
	 * @param Request $request
	 * @param TasksService $service
	 * @return void
	 */
	public function index(Request $request, TasksService $service){
		try {
			$this->data['data'] = $service->getDataList($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}

		return response()->json($this->data);
	}

	/**
	 * @title 添加任务
	 *
	 * @param Request $request
	 * @param TasksService $service
	 * @return void
	 */
	public function add(Request $request, TasksService $service){
		try {
			$this->data['data'] = $service->create($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}

		return response()->json($this->data);
	}

	/**
	 * @title 编辑任务
	 *
	 * @param Request $request
	 * @param TasksService $service
	 * @return void
	 */
	public function edit(Request $request, TasksService $service){
		try {
			$this->data['data'] = $service->update($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}

		return response()->json($this->data);
	}

	/**
	 * @title 删除任务
	 *
	 * @param Request $request
	 * @param TasksService $service
	 * @return void
	 */
	public function delete(Request $request, TasksService $service){
		try {
			$this->data['data'] = $service->delete($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}

		return response()->json($this->data);
	}
}
