package com.auto.clicker.autoclicker.room.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Delete;
import androidx.room.Query;
import androidx.room.Transaction;
import androidx.room.Update;

import com.auto.clicker.autoclicker.room.SolutionWithEventsAndPoints;
import com.auto.clicker.autoclicker.room.entity.Solution;

import java.util.List;

@Dao
public interface SolutionDao {
    @Insert
    long insertSolution(Solution solution); // 返回新插入的 solutionId

    @Query("SELECT * FROM solutions")
    List<Solution> getAllSolutions();

    @Query("SELECT * FROM solutions WHERE solutionId = :solutionId LIMIT 1")
    Solution getSolutionById(long solutionId);

    @Query("SELECT * FROM solutions WHERE solution_name = :solutionName LIMIT 1")
    Solution getSolutionByName(String solutionName);

    @Delete
    int deleteSolution(Solution solution); // 返回删除的行数

    @Update
    int updateSolution(Solution solution); // 返回更新的行数

    // 在 SolutionDao 中添加
    @Transaction // 表示这是一个事务操作，确保数据一致性
    @Query("SELECT * FROM solutions WHERE solutionId = :solutionId LIMIT 1")
    SolutionWithEventsAndPoints getSolutionWithEventsAndPoints(long solutionId);

    // 也可以获取所有方案及其事件
    @Transaction
    @Query("SELECT * FROM solutions")
    List<SolutionWithEventsAndPoints> getAllSolutionsWithEventsAndPoints();
}
