import { BaseService, service } from '/@/cool';

// 钉钉配置服务
class DingtalkConfigService extends BaseService {
	namespace = '/admin/dingtalk/config';

	// 验证配置
	async validate(data: any) {
		return this.request({
			url: '/validate',
			method: 'POST',
			data
		});
	}

	// 保存或更新配置
	async saveOrUpdate(data: any) {
		return this.request({
			url: '/saveOrUpdate',
			method: 'POST',
			data
		});
	}

	// 获取配置
	async getConfig() {
		return this.request({
			url: '/config',
			method: 'GET'
		});
	}
}

// 钉钉同步服务
class DingtalkSyncService extends BaseService {
	namespace = '/admin/dingtalk/sync';

	// 触发同步
	async trigger() {
		return this.request({
			url: '/trigger',
			method: 'POST'
		});
	}

	// 获取同步状态
	async getStatus() {
		return this.request({
			url: '/status',
			method: 'GET'
		});
	}
}

// 钉钉同步日志服务
class DingtalkSyncLogService extends BaseService {
	namespace = '/admin/dingtalk/sync';
}

// 钉钉部门服务
class DingtalkDepartmentService extends BaseService {
	namespace = '/admin/dingtalk/department';

	// 获取部门树
	async getTree() {
		return this.request({
			url: '/tree',
			method: 'GET'
		});
	}

	// 获取部门员工
	async getDepartmentUsers(params: any) {
		return this.request({
			url: '/users',
			method: 'GET',
			params
		});
	}
}

// 注册服务
service.dingtalk = {
	config: new DingtalkConfigService(),
	sync: new DingtalkSyncService(),
	syncLog: new DingtalkSyncLogService(),
	department: new DingtalkDepartmentService()
};

export default service.dingtalk;
