<?php

namespace App\Services;

use App\Models\MemberUser;
use Illuminate\Support\Facades\DB;
use Slowlyo\OwlAdmin\Services\AdminService;

/**
 * 用户管理
 *
 * @method MemberUser getModel()
 * @method MemberUser|\Illuminate\Database\Query\Builder query()
 */
class MemberUserService extends AdminService
{
	protected string $modelName = MemberUser::class;

	public function list()
	{
		$data = parent::list();
		$userState = admin_dict()->getAll('user_status');
		$userGender = admin_dict()->getAll('user_gender');

		collect($data['items'])->each(function ($item) use ($userState, $userGender) {
			$item->state = $userState[$item->state]['value'] ?? $item->state;
			$item->gender = $userGender[$item->gender]['value'] ?? $item->gender;
			$districtRegion = $item->load('region')->region;
			unset($item->region);
			$item->register_area = $districtRegion->mergerName ?? $item->register_area;
		});
        return $data;
	}

}
