package com.alttd.altitudeweb.database.web_db.forms;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.UUID;

public interface AppealMapper {

    @Insert("""
            INSERT INTO appeals (uuid, username, historyType, historyId, reason, created_at, send_at, e_mail, assigned_to)
            VALUES (#{uuid}, #{username}, #{historyType}, #{historyId}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
            """)
    void createAppeal(Appeal appeal);

    @Select("""
            SELECT id, uuid, historyType, historyId, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
            FROM appeals
            WHERE id = #{id}
            """)
    Appeal getAppealById(int id);

    @Select("""
            SELECT id, uuid, historyType, historyId, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
            FROM appeals
            WHERE uuid = #{uuid}
            """)
    List<Appeal> getAppealsByUuid(String uuid);

    @Update("""
            UPDATE appeals SET send_at = NOW()
            WHERE id = #{id}
            """)
    void markAppealAsSent(@Param("id") UUID id);

    @Update("""
            UPDATE appeals SET assigned_to = #{assignedTo}
            WHERE id = #{id}
            """)
    void assignAppeal(@Param("id") UUID id, @Param("assignedTo") Long assignedTo);
}
