package com.lion.lionwebsite.Dao.normal;

import com.lion.lionwebsite.Domain.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Insert("insert into User (AuthCode, username) values (#{AuthCode}, #{username})")
    void insertUser(User user);

    @Select("select * from User where AuthCode=#{AuthCode}")
    User selectUserByAuthCode(String AuthCode);

    @Select("select AuthCode from User")
    String[] selectAllAuthCode();

    @Select("select AuthCode from User")
    String[] selectEnableAuthCode();

    @Select("select * from User")
    User[] selectAllUser();

    @Update("update User set AuthCode=#{newAuthCode} where AuthCode=#{AuthCode}")
    void updateAuthCode(@Param("AuthCode") String AuthCode, @Param("newAuthCode") String newAuthCode);

    @Update("update User set username=#{newUsername} where AuthCode=#{AuthCode}")
    void updateUsername(@Param("AuthCode") String AuthCode, @Param("newUsername") String newUsername);

    @Update("update User set lastAccessTime=#{lastAccessTime} where AuthCode=#{AuthCode}")
    void updateLastAccessTime(@Param("lastAccessTime") String lastAccessTime, @Param("AuthCode") String AuthCode);

    @Update("update User set isEnable=#{isEnable} where id=#{id}")
    void updateIsEnableById(@Param("id") int id, @Param("isEnable") boolean isEnable);

    @Delete("delete from User where AuthCode=#{AuthCode}")
    void deleteUserByAuthCode(String AuthCode);

    @Select("select count(AuthCode) from User where AuthCode=#{AuthCode}")
    int isExist(String AuthCode);
}
