package com.huimv.admin.service.primary.impl;

import com.huimv.admin.domain.primary.SysAccountEntity;
import com.huimv.admin.repo.primary.SysAccountEntityRepository;
import com.huimv.admin.service.primary.ILoginService;
import com.huimv.admin.utils.Result;
import com.huimv.admin.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements ILoginService {

    @Autowired
    private SysAccountEntityRepository sysAccountEntityRepo;

    @Override
    public Result login(String accountName, String password) {
        //Step1:判断账户状态
        //Step2:读取菜单组
        SysAccountEntity accountEntity = sysAccountEntityRepo.findByAccountName(accountName, password);
        if (accountEntity == null) {
//            throw new PlatformException("The account or password is wrong.", "该账号不存在或密码错误.");
            return new Result(10002, "账号不存在或密码错误.", false);
        }
        int status = accountEntity.getAccountStatus();
        if (status == 0) {
            return new Result(10003, "该账号未启用.", false);
//            throw new PlatformException("10003", "该账号未启用.");
        }
        if (status == -1) {
            return new Result(10004, "该账号已暂停使用.", false);
//            throw new PlatformException("10004", "该账号已暂停使用.");
        }
        int accountId = accountEntity.getId();
        System.out.println("accountId>>"+accountId);
//        List<SysMenuEntity> menuEntityList = sysMenuEntityRepo.findByAccountId(accountId);
//        return new Result(ResultCode.SUCCESS, menuEntityList);
        return new Result(ResultCode.SUCCESS,accountEntity);
    }

    @Override
    public Result logout() {
        return null;
    }
}
