//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.luozhihui.project.mapper;

import com.luozhihui.project.entity.Category;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CategoryMapper {
    @Select({"SELECT * FROM category WHERE status = 1 ORDER BY sort ASC"})
    List<Category> findAllCategories();

    @Select({"SELECT * FROM category WHERE id = #{id}"})
    Category findById(@Param("id") Long id);

    @Insert({"INSERT INTO category (name, description, sort, status, createTime, updateTime) VALUES (#{name}, #{description}, #{sort}, #{status}, NOW(), NOW())"})
    @Options(
            useGeneratedKeys = true,
            keyProperty = "id"
    )
    int insert(Category category);

    @Update({"UPDATE category SET name = #{name}, description = #{description}, sort = #{sort}, status = #{status}, updateTime = NOW() WHERE id = #{id}"})
    int update(Category category);

    @Update({"UPDATE category SET status = 0, updateTime = NOW() WHERE id = #{id}"})
    int deleteById(@Param("id") Long id);

    @Select({"SELECT COUNT(*) FROM category WHERE name = #{name} AND status = 1"})
    int checkNameExists(@Param("name") String name);
}
