func AuthAdmin(email, pass string, db *services.MySQL) (*Admin, *app.Msg, error) {
	const (
		ADMIN_AUTH_SQL = "SELECT id, name, password, status  FROM admin_users WHERE email=?"
	)
	var id, name, bcryptpass, status string

	if len(email) == 0 || len(pass) == 0 {
		return nil, app.NewErrMsg("The email or password is empty."), nil
	}

	rows, err := db.Query(ADMIN_AUTH_SQL, email)
	if err != nil {
		return nil, nil, err
	}
	defer rows.Close()

	if !rows.Next() {
		return nil, app.NewErrMsg("The email or password is incorrect."), nil
	}

	rows.Scan(&id, &name, &bcryptpass, &status)
	perr := bcrypt.CompareHashAndPassword([]byte(bcryptpass), []byte(pass))
	if perr != nil {
		return nil, app.NewErrMsg("The email or password is incorrect."), nil
	}
	if status == "inactive" {
		return nil, app.NewErrMsg("Please contact sysadmin"), nil
	}
	return &Admin{ID: id, Name: name, Email: email}, nil, nil
}
func ListAdmins(db *services.MySQL) (*Admins, error) {
	const (
		ADMINS_LIST_SQL = "SELECT id, name, email, password, status FROM admin_users"
	)
	var (
		results  Admins
		id       string
		name     string
		email    string
		password string
		status   string
	)
	rows, err := db.Query(ADMINS_LIST_SQL)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		rows.Scan(&id, &name, &email, &password, &status)
		results = append(results,
			&Admin{
				ID:       id,
				Name:     name,
				Email:    email,
				Password: password,
				Status:   status,
			})
	}
	return &results, nil
}
func ListBloodBanks(db *services.MySQL) (*BloodBanks, error) {
	const (
		BBANK_LIST_SQL = "SELECT id, name, type, location, created FROM organisations"
	)
	var (
		results  BloodBanks
		id       string
		name     string
		typ      string
		location *geo.Point
		created  string
	)
	rows, err := db.Query(BBANK_LIST_SQL)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		rows.Scan(&id, &name, &typ, &location, &created)
		results = append(results,
			&BloodBank{
				ID:       id,
				Name:     name,
				Type:     typ,
				Location: location,
				Created:  created,
			})
	}
	return &results, nil

}
func ListRequests(db *services.MySQL) (*Requests, error) {
	const (
		REQUEST_LIST_SQL = "SELECT requests.id, users.id, users.name, date_of_requirement, requests.location, requests.blood, requests.comments, requests.mobile, requests.created FROM `requests` JOIN users ON requests.user_id = users.id"
	)

	var (
		results  Requests
		id       string
		userId   string
		userName string
		name     string
		date     string
		location *geo.Point
		blood    string
		comments string
		mobile   string
		created  string
	)
	rows, err := db.Query(REQUEST_LIST_SQL)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		rows.Scan(&id, &userId, &name, &date, &location, &blood, &comments, &mobile, &created)
		results = append(results,
			&Request{
				ID:       id,
				UserID:   userId,
				UserName: name,
				Date:     date,
				Location: location,
				Blood:    blood,
				Comments: comments,
				Mobile:   mobile,
				Created:  created,
			})

		fmt.Println(Request{
			ID:       id,
			UserID:   userId,
			UserName: userName,
			Date:     date,
			Location: location,
			Blood:    blood,
			Comments: comments,
			Mobile:   mobile,
			Created:  created,
		})
	}
	return &results, nil

}
func ListDonors(db *services.MySQL) (*Donors, error) {
	const (
		DONORS_LIST_SQL = "SELECT id, name, mobile, blood, sex, location, place_id, created FROM users"
	)
	var (
		results  Donors
		id       string
		name     string
		mobile   string
		blood    string
		gender   string
		location *geo.Point
		place    string
		created  string
	)
	rows, err := db.Query(DONORS_LIST_SQL)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		rows.Scan(&id, &name, &mobile, &blood, &gender, &location, &place, &created)
		results = append(results,
			&Donor{
				ID:       id,
				Name:     name,
				Mobile:   mobile,
				Blood:    blood,
				Gender:   gender,
				Location: location,
				Place:    place,
				Created:  created,
			})
	}
	return &results, nil

}