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

use Illuminate\Http\Request;
use App\Http\Controllers\BaseController;
use Modules\Account\Services\AdminFamilyService;

class Family extends BaseController {

	/**
	 * @title 家庭列表
	 *
	 * @param Request $request
	 * @param AdminFamilyService $service
	 * @return void
	 */
	public function index(Request $request, AdminFamilyService $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 AdminFamilyService $service
	 * @return void
	 */
	public function add(Request $request, AdminFamilyService $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 AdminFamilyService $service
	 * @return void
	 */
	public function edit(Request $request, AdminFamilyService $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 AdminFamilyService $service
	 * @return void
	 */
	public function delete(Request $request, AdminFamilyService $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);
	}

	/**
	 * @title 家庭详情
	 *
	 * @param Request $request
	 * @param AdminFamilyService $service
	 * @return void
	 */
	public function detail(Request $request, AdminFamilyService $service) {
		try {
			$this->data['data'] = $service->detail($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return response()->json($this->data);
	}

	/**
	 * @title 家庭成员列表
	 *
	 * @param Request $request
	 * @param AdminFamilyService $service
	 * @return void
	 */
	public function members(Request $request, AdminFamilyService $service) {
		try {
			$this->data['data'] = $service->getMembers($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return response()->json($this->data);
	}

	/**
	 * @title 添加家庭成员
	 *
	 * @param Request $request
	 * @param AdminFamilyService $service
	 * @return void
	 */
	public function addMember(Request $request, AdminFamilyService $service) {
		try {
			$this->data['data'] = $service->addMember($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return response()->json($this->data);
	}

	/**
	 * @title 移除家庭成员
	 *
	 * @param Request $request
	 * @param AdminFamilyService $service
	 * @return void
	 */
	public function removeMember(Request $request, AdminFamilyService $service) {
		try {
			$this->data['data'] = $service->removeMember($request);
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return response()->json($this->data);
	}
}
