package com.example.service;

import com.example.bean.Doctor;
import com.example.bean.Worker;
import com.example.mapper.DoctorMapper;
import com.example.mapper.WorkerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkerService {
    @Autowired
    private WorkerMapper workerMapper;
    @Autowired
    private DoctorMapper doctorMapper;
    public Worker getWorkerById(String userid)//获得对应id的管理员
    {
        Worker worker = workerMapper.getWorkerById(userid);
        return worker;
    }

    public int regWorker(Worker worker)//管理员的注册
    {
            int result = workerMapper.reg(worker);
            boolean b = result == 1;
            if(b)
                return 0;//返回0表示注册成功
            else
                return 2;//返回2表示注册失败
    }

    public int updateWorkerEnabled(boolean enabled,String userid)//更新医生的enabled属性
    {
        return workerMapper.updateWorkerEnabled(enabled,userid);//1表示更新成功，其他表示失败
    }

    public int deleteWorker(String userid)//根据id删除管理员
    {
        return workerMapper.deleteUserByUserid(userid);
    }

    public int updateWorker(Worker worker)//更新用户信息（不包括enabled和qualification）
    {
        return workerMapper.updateWorker(worker);
    }
    public List<Doctor> getAllDoctors()//获得所有的医生（不包含公共医生）
    {
        return doctorMapper.showAllDoctors();
    }
}
