<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tasteby.mapper.DaemonConfigMapper">

    <resultMap id="daemonConfigResultMap" type="com.tasteby.domain.DaemonConfig">
        <id property="id" column="id"/>
        <result property="scanEnabled" column="scan_enabled" javaType="boolean"/>
        <result property="scanIntervalMin" column="scan_interval_min"/>
        <result property="processEnabled" column="process_enabled" javaType="boolean"/>
        <result property="processIntervalMin" column="process_interval_min"/>
        <result property="processLimit" column="process_limit"/>
        <result property="lastScanAt" column="last_scan_at"/>
        <result property="lastProcessAt" column="last_process_at"/>
        <result property="updatedAt" column="updated_at"/>
    </resultMap>

    <select id="getConfig" resultMap="daemonConfigResultMap">
        SELECT id, scan_enabled, scan_interval_min, process_enabled, process_interval_min,
               process_limit, last_scan_at, last_process_at, updated_at
        FROM daemon_config
        WHERE id = 1
    </select>

    <update id="updateConfig">
        UPDATE daemon_config
        <set>
            scan_enabled = #{scanEnabled, javaType=boolean, jdbcType=NUMERIC},
            scan_interval_min = #{scanIntervalMin},
            process_enabled = #{processEnabled, javaType=boolean, jdbcType=NUMERIC},
            process_interval_min = #{processIntervalMin},
            process_limit = #{processLimit},
            updated_at = SYSTIMESTAMP,
        </set>
        WHERE id = 1
    </update>

    <update id="updateLastScan">
        UPDATE daemon_config SET last_scan_at = SYSTIMESTAMP WHERE id = 1
    </update>

    <update id="updateLastProcess">
        UPDATE daemon_config SET last_process_at = SYSTIMESTAMP WHERE id = 1
    </update>

</mapper>
