package com.lion.lionwebsite.Dao.normal;

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

import java.util.ArrayList;

@Mapper
public interface TagMapper {
    @Insert("insert into tag (tag) values (#{tag})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertTag(Tag tag);

//    @Select("select id, tag, usage from tag where id=#{id}")
//    Tag selectTagById(int id);
//
//    @Select("select id from tag where tag=#{tag}")
//    int selectTidByTag(String tag);

    @Select("select count(id) from tag where tag=#{tag}")
    int selectTagExistByTag(String tag);

    @Select("select count(id) from tag where id=#{id}")
    int selectTagExistById(int id);


    @Select("select id, tag, usage from tag")
    ArrayList<Tag> selectAllTag();

    @Delete("delete from tag where id=#{id}")
    void deleteTagById(int id);

    @Select("select count(id) from galleryTag where tid=#{tid}")
    int selectTagUsage(int tid);

    @Select("select count(id) from galleryTag where gid=#{gid} and tid=#{tid}")
    int selectIsMark(@Param("gid") int gid, @Param("tid") int tid);

    @Select("select tid from galleryTag where gid=#{gid}")
    ArrayList<Integer> selectTagByGid(int gid);

    @Insert("insert into galleryTag (gid, tid) values (#{gid}, #{tid})")
    int markTag(@Param("gid") int gid, @Param("tid") int tid);

    @Delete("delete from galleryTag where gid=#{gid} and tid=#{tid}")
    int disMarkTag(@Param("gid") int gid, @Param("tid") int tid);

    @Select("select gid, tid from galleryTag")
    ArrayList<TagMark> selectAllMark();

    @Update("update tag set usage=usage+1 where id=#{tid}")
    void incrTagUsage(int tid);

    @Update("update tag set usage=usage-1 where id=#{tid}")
    void decrTagUsage(int tid);

    @Delete("delete from galleryTag where gid=#{gid}")
    void disMarkTagByGid(int gid);
}
