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


import com.fshark.overseas.advert.entity.ServerRoleAccount;
import com.fshark.overseas.advert.entity.mapper.ServerRoleAccountMapper;
import com.fshark.overseas.advert.modle.AppsFlyerEvent;
import com.fshark.overseas.advert.modle.AppsFlyerWithAccountEvent;
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 ServerRoleDao {


    @SqlQuery("SELECT * FROM appsflyer_server_role WHERE game_id=:game_id AND uid=:uid AND platform =:platform AND register_server_id = :serverid AND event_type =:event_type order by event_time desc limit 1")
    @RegisterRowMapper(ServerRoleAccountMapper.class)
    Optional<ServerRoleAccount> findByPrimary(@BindBean AppsFlyerEvent event, @Bind("serverid") String serverid, @Bind("event_type") String event_type);

    @SqlUpdate("insert into appsflyer_server_role (region, did, uid,  platform, game_id, media_source, campaign_id, ad_set_id, ad_id ,time_zone,register_server_id,role_id,event_type,event_time)" +
            " values (:region, :did, :uid, :platform, :game_id, :media_source, :campaign_id, :ad_set_id , :ad_id ,:time_zone, :register_server_id ,:role_id,'activation',:reg_event_time)")
    void insertServerRole(@BindBean AppsFlyerWithAccountEvent event);

    @SqlUpdate("insert into appsflyer_server_role (region, did, uid,  platform, game_id, media_source, campaign_id, ad_set_id, ad_id ,time_zone,register_server_id,role_id,event_type,event_time)" +
            " values (:region, :did, :uid, :platform, :game_id, :media_source, :campaign_id, :ad_set_id , :ad_id ,:time_zone, :register_server_id ,:role_id,'rolelogin',:reg_event_time)")
    void inserttServerLogin(@BindBean AppsFlyerWithAccountEvent event);
}
