package com.fshark.overseas.advert.entity.dao;


import com.fshark.overseas.advert.entity.GameAccount;
import com.fshark.overseas.advert.entity.RegisterAccount;
import com.fshark.overseas.advert.entity.mapper.GameAccountMapper;
import com.fshark.overseas.advert.entity.mapper.RegisterAccountMapper;
import com.fshark.overseas.advert.modle.AppsFlyerEvent;
import org.apache.kafka.common.protocol.types.Field;
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

import java.util.Optional;

public interface GameAccountDao {

    /**
     * 根据主键获取当前账户信息
     *
     * @param
     * @return
     */
    @SqlQuery("SELECT * FROM appsflyer_activation_devices WHERE game_id=:game_id AND uid=:uid And platform =:platform AND event_type =:event_type order by event_time desc limit 1")
    @RegisterRowMapper(GameAccountMapper.class)
    Optional<GameAccount> findByPrimary(@BindBean AppsFlyerEvent event, @Bind("event_type") String event_type);


    @SqlUpdate("insert into appsflyer_activation_devices (`platform`,`did`, `uid`, `region`, `game_id`,`media_source`,`campaign_id`,`ad_set_id`,`ad_id`, `time_zone`,`event_type`,`event_time`) " +
            "values ( :platform,:did ,:uid, :region, :game_id, :media_source, :campaign_id,:ad_set_id, :ad_id, :time_zone,'activation',:reg_time) ")
    void insertActivition(@BindBean AppsFlyerEvent event, @Bind("reg_time") String reg_time);


    @SqlUpdate("insert into appsflyer_activation_devices (`platform`,`did`, `uid`, `region`, `game_id`,`media_source`,`campaign_id`,`ad_set_id`,`ad_id`, `time_zone`,`event_type`,`event_time`) " +
            " values ( :platform,:did ,:uid, :region, :game_id, :media_source, :campaign_id,:ad_set_id, :ad_id,  :time_zone,'register',:reg_time ) ")
    void insertRegister(@BindBean AppsFlyerEvent value, @Bind("reg_time") String reg_time);


    @SqlUpdate("insert into appsflyer_activation_devices (`platform`,`did`, `uid`, `region`, `game_id`,`media_source`,`campaign_id`,`ad_set_id`,`ad_id`, `time_zone`,`event_type`,`event_time`) " +
            " values ( :platform,:did ,:uid, :region, :game_id, :media_source, :campaign_id,:ad_set_id, :ad_id, :time_zone,'rolelogin',:event_time ) ")
    void insertRoleLogin(@BindBean AppsFlyerEvent value);

    @SqlUpdate("insert into appsflyer_activation_devices (`platform`,`did`, `uid`, `region`, `game_id`,`media_source`,`campaign_id`,`ad_set_id`,`ad_id`, `time_zone`,`event_type`,`event_time`) " +
            " values ( :platform,:did ,:uid, :region, :game_id, :media_source, :campaign_id,:ad_set_id, :ad_id, :time_zone,'purchase',:event_time ) ")
    void insertPauchase(@BindBean AppsFlyerEvent value);
}
