package com.lion.lionwebsite.Dao.normal;

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


@Mapper
public interface GalleryMapper {


    @Insert("insert into gallery" +
            " (gid, name, link, language, pages, status, fileSize, createTime, proceeding, resolution, displayFileSize, downloader, mode, thumb_link)\n" +
            "  values (#{gid}, #{name}, #{link}, #{language}, #{pages}, #{status}, #{fileSize}, #{createTime}, #{proceeding}, #{resolution}, #{displayFileSize}, #{downloader}, #{mode}, #{thumb_link})")
    void insertGallery(Gallery gallery);

    @Select("select * from gallery where link=#{link}")
    Gallery selectGalleryByLink(String link);

    @Select("select * from gallery where gid=#{gid}")
    Gallery selectGalleryByGid(int gid);

    @Select("select name from gallery where gid=#{gid}")
    String selectGalleryNameByGid(int gid);

    @Select("select * from gallery where downloader=#{downloader}")
    Gallery[] selectGalleryByDownloader(int downloader);

    @Select("select * from gallery where status in ('已提交', '下载中')")
    Gallery[] selectUnDoneGalleries();

    @Select("select * from gallery order by createTime")
    Gallery[] selectAllGallery();

    @Select("select * from gallery where name like #{name} limit 1")
    Gallery selectGalleryByName(String name);


    @Update("""
            update gallery set name=#{name}, link=#{link}, language=#{language},
                                    pages=#{pages}, status=#{status}, fileSize=#{fileSize}, createTime=#{createTime},
                                    proceeding=#{proceeding}, resolution=#{resolution}, displayFileSize=#{displayFileSize}, mode=#{mode}
                    where gid=#{gid}""")
    void updateGallery(Gallery gallery);

    @Update("update gallery set downloader=#{downloader} where downloader=#{oldDownloader}")
    void updateGalleryDownloader(@Param("downloader") int downloader, @Param("oldDownloader") int oldDownloader);

    @Delete("delete from gallery where gid=#{gid}")
    void deleteGalleryByGid(Integer gid);
}
