package com.gameplatform.server.mapper.lock;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface LockMapper {

    /**
     * Try to acquire a named MySQL advisory lock. Returns 1 if acquired, 0 if timeout, NULL on error.
     */
    @Select("SELECT GET_LOCK(#{name}, #{timeoutSeconds})")
    Integer getLock(@Param("name") String name, @Param("timeoutSeconds") int timeoutSeconds);

    /**
     * Release the named advisory lock. Returns 1 if released, 0 if not held, NULL on error.
     */
    @Select("SELECT RELEASE_LOCK(#{name})")
    Integer releaseLock(@Param("name") String name);
}

