package com.schisandra.auth.infra.basic.service.impl;


import com.schisandra.auth.infra.basic.dao.SchisandraAuthUserDao;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
import com.schisandra.auth.infra.basic.entity.table.SchisandraAuthUserTableDef;
import com.schisandra.auth.infra.basic.service.SchisandraAuthUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (SchisandraAuthUser)表服务实现类
 *
 * @author schisandra
 * @since 2024-03-21 20:15:44
 */
@Service("SchisandraAuthUserService")
public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService {

    @Resource
    private SchisandraAuthUserDao schisandraAuthUserDao;

    @Override
    public SchisandraAuthUser queryByEmail(String email) {
        return schisandraAuthUserDao.selectOneByCondition(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.EMAIL.eq(email)
                .and(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.IS_DELETED.eq(0)));
    }

    @Override
    public SchisandraAuthUser queryByPhone(String phone) {
        return schisandraAuthUserDao.selectOneByCondition(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.PHONE.eq(phone)
                .and(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.IS_DELETED.eq(0)));
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SchisandraAuthUser queryById(Long id) {
        return this.schisandraAuthUserDao.selectOneById(id);
    }

    /**
     * 新增数据
     *
     * @param schisandraAuthUser 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean insert(SchisandraAuthUser schisandraAuthUser) {

        return this.schisandraAuthUserDao.insert(schisandraAuthUser) > 0;
    }

    /**
     * 修改数据
     *
     * @param schisandraAuthUser 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SchisandraAuthUser schisandraAuthUser) {
        return this.schisandraAuthUserDao.update(schisandraAuthUser, true);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.schisandraAuthUserDao.deleteById(id) > 0;
    }


    @Override
    public int insertAuthUserByOauth(SchisandraAuthUser schisandraAuthUser) {
        return schisandraAuthUserDao.insert(schisandraAuthUser);
    }

}
