<?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 Modules\Member\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\BaseController;
use Modules\Member\Services\FieldsService;

class Field extends BaseController {

	/**
	 * @title 获取字段列表
	 *
	 * @param Request $request
	 * @param FieldsService $service
	 * @return void
	 */
	public function index(Request $request, FieldsService $service) {
		try {
			$this->data['data'] = $service->getDataList($request);
			$this->data['message'] = '获取成功';
		} catch (\Throwable $th) {
			$this->data['code'] = 0;
			$this->data['message'] = $th->getMessage();
		}

		return $this->data;
	}

	/**
	 * @title 添加字段
	 *
	 * @param Request $request
	 * @param FieldsService $service
	 * @return void
	 */
	public function add(Request $request, FieldsService $service) {
		try {
			$this->data['data'] = $service->create($request);
			$this->data['message'] = '添加成功';
		} catch (\Throwable $th) {
			$this->data['code'] = 0;
			$this->data['message'] = $th->getMessage();
		}

		return $this->data;
	}

	/**
	 * @title 编辑字段
	 *
	 * @param Request $request
	 * @param FieldsService $service
	 * @return void
	 */
	public function edit(Request $request, FieldsService $service) {
		try {
			$this->data['data'] = $service->update($request);
			$this->data['message'] = '编辑成功';
		} catch (\Throwable $th) {
			$this->data['code'] = 0;
			$this->data['message'] = $th->getMessage();
		}

		return $this->data;
	}

	/**
	 * @title 删除字段
	 *
	 * @param Request $request
	 * @param FieldsService $service
	 * @return void
	 */
	public function delete(Request $request, FieldsService $service) {
		try {
			$this->data['data'] = $service->delete($request);
			$this->data['message'] = '删除成功';
		} catch (\Throwable $th) {
			$this->data['code'] = 0;
			$this->data['message'] = $th->getMessage();
		}

		return $this->data;
	}

	/**
	 * @title 字段列表
	 *
	 * @param Request $request
	 * @param FieldsService $service
	 * @return void
	 */
	public function lists(Request $request, FieldsService $service){
		try {
			$this->data['data'] = $service->getFieldList($request);
			$this->data['message'] = '获取成功';
		} catch (\Throwable $th) {
			$this->data['code'] = 0;
			$this->data['message'] = $th->getMessage();
		}

		return $this->data;
	}

	/**
	 * @title 列表字段配置
	 *
	 * @param Request $request
	 * @param FieldsService $service
	 * @return void
	 */
	public function setting(Request $request, FieldsService $service){
		try {
			$this->data['data'] = $service->getFieldSetting($request);
			$this->data['message'] = '获取成功';
		} catch (\Throwable $th) {
			$this->data['code'] = 0;
			$this->data['message'] = $th->getMessage();
		}

		return $this->data;
	}
}
