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


import com.schisandra.auth.infra.basic.dao.SchisandraAuthSocialUserDao;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthSocialUser;
import com.schisandra.auth.infra.basic.entity.table.SchisandraAuthSocialUserTableDef;
import com.schisandra.auth.infra.basic.service.SchisandraAuthSocialUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 表服务实现类
 *
 * @author landaiqing
 * @since 2024-05-23 20:07:57
 */
@Service("SchisandraAuthSocialUserService")
public class SchisandraAuthSocialUserServiceImpl implements SchisandraAuthSocialUserService {

    @Resource
    private SchisandraAuthSocialUserDao schisandraAuthSocialUserDao;

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

    /**
     * 新增数据
     *
     * @param schisandraAuthSocialUser 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(SchisandraAuthSocialUser schisandraAuthSocialUser) {
        return this.schisandraAuthSocialUserDao.insert(schisandraAuthSocialUser);
    }

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

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


    @Override
    public SchisandraAuthSocialUser selectByUuidAndType(String uuid, String type) {
        return schisandraAuthSocialUserDao.selectOneByCondition(
                SchisandraAuthSocialUserTableDef.SCHISANDRA_AUTH_SOCIAL_USER.UUID.eq(uuid)
                        .and(SchisandraAuthSocialUserTableDef.SCHISANDRA_AUTH_SOCIAL_USER.SOURCE.eq(type)
                                .and(SchisandraAuthSocialUserTableDef.SCHISANDRA_AUTH_SOCIAL_USER.IS_DELETED.eq(0))));
    }

    @Override
    public int insertAuthSocialUserByOauth(SchisandraAuthSocialUser schisandraAuthSocialUser) {
        return schisandraAuthSocialUserDao.insert(schisandraAuthSocialUser);
    }

    @Override
    public int updateByOauth(SchisandraAuthSocialUser schisandraAuthSocialUser) {
        return schisandraAuthSocialUserDao.update(schisandraAuthSocialUser, true);
    }

}
