package users

import (
	"git.ali33.ru/fcg-xvii/rest"
	"git.ali33.ru/fcg-xvii/rest/example_chat/chat"
)

type Auth struct {
	Name     string `rest:"required"`
	Password string `rest:"required"`
}

func (s *Auth) Validate(req rest.IRequest) rest.IResponse {
	if req.IsAuth() {
		return req.ResponseError(500, rest.ErrorMessage("ErrAuth", "already auth"))
	}
	return nil
}

func (s *Auth) Execute(req rest.IRequest) rest.IResponse {
	core := req.Core().(*chat.Chat)
	user, check := core.Auth(s.Name, s.Password)
	if !check {
		return req.ResponseError(500, rest.ErrorMessage("ErrAuthData", "user is not found"))
	}
}
