<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use App\Services\Auth\MenuService;

class SystemSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void {
		$this->insertSettingDict();
		$this->insertDataAuthDict();
		$this->insertAdsDict();
		$this->addModelFieldTypeDict();
		$this->insertClientMenuPosition();
		$this->insertPermissions();
	}

	public function insertSettingDict(){
		$group_id = DB::table('system_dict_groups')->insertGetId([
			'parent_id'  => 0,
			'title'      => '配置分组',
			'name'       => 'setting_group',
			'status'     => 1,
			'created_at' => date('Y-m-d H:i:s'),
			'updated_at' => date('Y-m-d H:i:s'),
		]);
		if($group_id){
			$dict = DB::table('system_dicts')->insert([
				['group_id' => $group_id, 'group_name' => 'setting_group', 'title' => '基础配置', 'values' => 'base', 'sort' => 1, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['group_id' => $group_id, 'group_name' => 'setting_group', 'title' => '上传配置', 'values' => 'upload', 'sort' => 1, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
			]);
			DB::table('system_configs')->insert([
				['name' => 'system_name', 'title' => '系统名称', 'values' => 'SentOS', 'type' => 'string', 'group' => 'base', 'sort' => 1, 'status' => 1, 'remark' => '系统名称', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['name' => 'system_logo', 'title' => '系统Logo', 'values' => '', 'type' => 'image', 'group' => 'base', 'sort' => 2, 'status' => 1, 'remark' => '系统Logo', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['name' => 'system_email', 'title' => '邮箱', 'values' => '', 'type' => 'string', 'group' => 'base', 'sort' => 6, 'status' => 1, 'remark' => '邮箱', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['name' => 'system_copyright', 'title' => '版权信息', 'values' => 'Copyright © 2019-2024 SentCMS All Rights Reserved.', 'type' => 'string', 'group' => 'base', 'sort' => 3, 'status' => 1, 'remark'   => '版权信息', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['name' => 'system_icp', 'title' => '备案信息', 'values' => '', 'type' => 'string', 'group' =>'base', 'sort' => 4, 'status' => 1, 'remark' => '备案信息', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['name' => 'upload_way', 'title' => '上传引擎', 'values' => 'public', 'type' => 'radio', 'group' =>'upload', 'sort' => 1, 'status' => 1, 'remark' => '上传引擎', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]
			]);
		}
	}

	public function insertDataAuthDict(){
		$group_id = DB::table('system_dict_groups')->insertGetId([
			'parent_id'  => 0,
			'title'      => '数据权限分组',
			'name'       => 'data_auth',
			'sort'    => 1,
			'status'    => 1,
			'created_at' => date('Y-m-d H:i:s'),
			'updated_at' => date('Y-m-d H:i:s'),
		]);
		if($group_id){
			DB::table('system_dicts')->insert([
				[
					'group_id'  => $group_id,
					'group_name' => 'data_auth',
					'title'     => '全部数据',
					'values'     => 'all',
					'sort'    => 1,
					'status'    => 1,
					'created_at' => date('Y-m-d H:i:s'),
					'updated_at' => date('Y-m-d H:i:s'),
				],
				[
					'group_id'  => $group_id,
					'group_name' => 'data_auth',
					'title'     => '本部门数据',
					'values'     => 'department',
					'sort'    => 2,
					'status'    => 1,
					'created_at' => date('Y-m-d H:i:s'),
					'updated_at' => date('Y-m-d H:i:s'),
				],
				[
					'group_id'  => $group_id,
					'group_name' => 'data_auth',
					'title'     => '本部门及以下数据',
					'values'     => 'department_sub',
					'sort'    => 3,
					'status'    => 1,
					'created_at' => date('Y-m-d H:i:s'),
					'updated_at' => date('Y-m-d H:i:s'),
				],
				[
					'group_id'  => $group_id,
					'group_name' => 'data_auth',
					'title'     => '仅自己数据',
					'values'     => 'self',
					'sort'    => 4,
					'status'    => 1,
					'created_at' => date('Y-m-d H:i:s'),
					'updated_at' => date('Y-m-d H:i:s'),
				]
			]);
		}
	}

	public function insertAdsDict(){
		$group_id = DB::table('system_dict_groups')->insertGetId([
			'parent_id'  => 0,
			'title'      => '广告位',
			'name'       => 'ads_places',
			'sort'    => 1,
			'status'    => 1,
			'created_at' => date('Y-m-d H:i:s'),
			'updated_at' => date('Y-m-d H:i:s'),
		]);
		if($group_id){
			DB::table('system_dicts')->insert([
				[
					'group_id'  => $group_id,
					'group_name' => 'ads_places',
					'title'     => '首页轮播',
					'values'     => 'index_banner',
					'sort'    => 2,
					'status'    => 1,
					'created_at' => date('Y-m-d H:i:s'),
					'updated_at' => date('Y-m-d H:i:s'),
				]
			]);
		}
	}

	public function insertClientMenuPosition(){
		$group_id = DB::table('system_dict_groups')->insertGetId([
			'parent_id'  => 0,
			'title'      => '菜单位置',
			'name'       => 'client_menu_position',
			'sort'    => 3,
			'status'    => 1,
			'created_at' => date('Y-m-d H:i:s'),
			'updated_at' => date('Y-m-d H:i:s'),
		]);

		if($group_id){
			DB::table('system_dicts')->insert([
				[
					'group_id'  => $group_id,
					'group_name' => 'client_menu_position',
					'title'     => '顶部菜单',
					'values'     => 'top',
					'sort'    => 1,
					'status'    => 1,
					'created_at' => date('Y-m-d H:i:s'),
					'updated_at' => date('Y-m-d H:i:s'),
				]
			]);
		}
	}
	/**
	 * @title 添加字典
	 *
	 * @return void
	 */
	public function addModelFieldTypeDict(){
		$group_id = DB::table('system_dict_groups')->insertGetId([
			'parent_id'  => 0,
			'title'      => '字段类型',
			'name'       => 'field_type',
			'status'     => 1,
			'created_at' => date('Y-m-d H:i:s'),
			'updated_at' => date('Y-m-d H:i:s'),
		]);
		if($group_id){
			$dict = DB::table('system_dicts')->insert([
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '单行文本', 'values' => 'string', 'sort' =>1, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '多行文本', 'values' => 'text', 'sort' => 2, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '单选按钮', 'values' => 'radio', 'sort' => 3, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '多选按钮', 'values' => 'checkbox', 'sort' => 4, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '下拉列表', 'values' => 'select', 'sort' => 5, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '字典选择', 'values' => 'sSelect', 'sort' => 5, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' =>date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '树形选择', 'values' => 'sSelectTree', 'sort' => 6, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '日期', 'values' => 'date', 'sort' => 6, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '日期时间', 'values' => 'datetime', 'sort' => 7, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '文件', 'values' => 'file', 'sort' => 8, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '图片', 'values' => 'image', 'sort' => 9, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '多图', 'values' => 'images', 'sort' => 10, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '富文本', 'values' => 'editor', 'sort' => 10, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '视频', 'values' => 'video', 'sort' => 10, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '音频', 'values' => 'audio', 'sort' => 10, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')],
				['group_id' => $group_id, 'group_name' => 'field_type', 'title' => '数字', 'values' => 'number', 'sort' => 3, 'status' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]
			]);
		}
	}

	public function insertPermissions(){
		$permissions = [
			['title' => '系统', 'name' => 'system', 'path' => '/system', 'component' => '', 'type' => 'menu', 'sort' => 100, 'children' => [
				['title' => '系统设置', 'name' => 'system.setting', 'path' => '/system/setting', 'component' => 'system/setting', 'type' => 'menu'],
				['title' => '城市数据', 'name' => 'system.area', 'path' => '/system/area', 'component' => 'system/area', 'type' => 'menu'],
				['title' => '字典管理', 'name' => 'system.dic', 'path' => '/system/dic', 'component' => 'system/dic', 'type' => 'menu'],
				['title' => '客户端管理', 'name' => 'system.client', 'path' => '/system/client', 'component' => 'system/client', 'type' => 'menu'],
				['title' => '模块管理', 'name' => 'system.modules', 'path' => '/system/modules', 'component' => 'system/modules', 'type' => 'menu'],
				['title' => '系统日志', 'name' => 'system.log', 'path' => '/system/log', 'component' => 'system/log', 'type' => 'menu'],
				['title' => '定时任务', 'name' => 'system.crontab', 'path' => '/system/crontab', 'component' => 'system/crontab', 'type' => 'menu'],
			]]
		];
		app(MenuService::class)->importMenu($permissions, 0);
	}
}
