package user

import (
	"errors"
	"gofiber.study.skcks.cn/global"
	"gofiber.study.skcks.cn/model/generic/models"
)

var (
	NotExists = errors.New("用户不存在")
)

type Service struct {
}

var Services *Service

func InitService() {
	Services = &Service{}
}

func (s *Service) GetUserByAccount(account string) (*models.User, error) {
	u := &models.User{
		Account: account,
	}

	has, err := global.DataSources.Get(u)
	if err != nil {
		return nil, err
	}

	if !has {
		return nil, NotExists
	}

	return u, nil
}
