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);

    @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);

    @Transaction
    @Query("SELECT * FROM solutions WHERE solutionId = :solutionId LIMIT 1")
    SolutionWithEventsAndPoints getSolutionWithEventsAndPoints(long solutionId);

    @Transaction
    @Query("SELECT * FROM solutions")
    List<SolutionWithEventsAndPoints> getAllSolutionsWithEventsAndPoints();

    @Query("UPDATE solutions SET solution_name = :newName WHERE solutionId = :solutionId")
    int updateSolutionName(long solutionId, String newName);

    @Query("DELETE FROM solutions WHERE solutionId = :solutionId")
    void deleteSolutionById(long solutionId);
}
