%%%-------------------------------------------------------------------
%%% @author  tyl
%%% @doc
%%%     樱花之礼-阶段抽奖头文件
%%% @end
%%% Created : 2021-03-10
%%%-------------------------------------------------------------------

%% 抽奖类型
-define(DRAW_TYPE_ONE, 1).      %% 单抽
-define(DRAW_TYPE_TEN, 2).      %% 十连抽

%% 日志类型
-define(LOG_TYPE_SERVER, 1).    %% 全服记录
-define(LOG_TYPE_PERSON, 2).    %% 个人记录

%% 日志缓存key
-define(LOG_KEY_SERVER(RoleId), {sakura_server_log, RoleId}).  %% 暂时未使用
-define(LOG_KEY_PERSON(RoleId, SubType), {sakura_person_log, RoleId, SubType}).

%% 商城缓存key
-define(SAKURA_GOODS(RoleId, SubType), {sakura_goods, RoleId, SubType}).

%% 日志长度
-define(LOG_LEN_SERVER_RARE,    20). % 20
-define(LOG_LEN_SERVER_EXTREME, 10). % 10
-define(LOG_LEN_PERSON, 3). % 30

%% 是否传闻
-define(SAKURA_TV, 1).

%% 奖励珍稀度
-define(SAKURA_NORMAL_REWARD,  0).  %% 普通
-define(SAKURA_RARE_REWARD,    1).  %% 珍稀
-define(SAKURA_EXTREME_REWARD, 2).  %% 极品

%% 活动数据
-record(sakura_data, {
	lucky_value = 0     %% 源樱值(幸运值,用于计算抽奖物品权重)
	,points     = 0     %% 积分(用于商城兑换)
	,free_times = 0     %% 已使用免费次数
}).

%% 玩家进程商城数据
-record(role_sakura_goods, {
	sub_type    = 0     %% 活动子Id
	,goods_id   = 0     %% 商城物品Id
	,exc_time   = 0     %% 兑换次数
}).

%% 个人日志
-record(sakura_per_log, {
	key         = 0     %% 键(非展示顺序，用于唯一确认记录) p.s. 从1开始每次+1
	,reward     = []    %% 奖励
	,time       = 0     %% 记录时间
}).

%% 全服日志
-record(sakura_server_log, {
	key         = 0     %% 自增Id（确认唯一记录）
	,role_id    = 0     %% 角色Id
	,tag        = 0     %% 奖励品质
	,reward     = []    %% 奖励
	,time       = 0     %% 记录时间
}).

%% ------------------------- 配置表 ---------------------------------
%% 键值表
-record(base_sakura_gift_key, {
	id      = 0
	,suit   = 0         %% 套数(不同活动子类型使用套数不同)
	,key    = ""
	,value  = ""
	,desc   = ""        %% 描述
}).

%% 奖励表
-record(base_sakura_gift_reward, {
	id           = 0    %% 奖励Id
	,act_id      = 0    %% 活动子Id
	,awards      = []   %% 奖励
	,weight      = 0    %% 基础权重
	,luck_start  = 0    %% 源樱值下限
	,luck_end    = 0    %% 源樱值上限
	,luck_weight = 0    %% 增加权重/每点源樱值(N/per M)
	,is_tv       = 0    %% 是否有传闻
	,tag         = 0    %% 标签(奖励档次)
}).

%% 积分兑换表
-record(base_sakura_gift_point_reward, {
	id          = 0    %% 奖励Id
	,act_id     = 0    %% 活动子Id
	,goods      = []   %% 兑换奖励
	,limit      = 0    %% 次数限制
	,points     = 0    %% 所需积分
}).

%% 积分补偿表
-record(base_sakura_gift_point_rest, {
	suit        = 0     %% 套数(同上)
	,point_min  = 0     %% 积分下限
	,point_max  = 0     %% 积分上限
	,reward     = []    %% 补偿奖励
}).

%% ------------------------- db ---------------------------------
%% 日志数据
%% 1. 全服日志
-define(SQL_SAVE_SAKURA_SERVER_LOG, <<"replace into sakura_server_log (`sub_type`, `id`, `role_id`, `tag`, `reward`, `time`) values (~p, ~p, ~p, ~p, '~ts', ~p)">>).
-define(SQL_SELECT_SAKURA_SERVER_LOG, <<"select `id`, `role_id`, `tag`, `reward`, `time` from sakura_server_log where `sub_type` = ~p">>).
-define(SQL_DELETE_SAKURA_SERVER_LOG, <<"delete from sakura_server_log where `sub_type` = ~p and `id` = ~p">>).
-define(SQL_DELETE_ALL_SAKURA_SERVER_LOG, <<"delete from sakura_server_log where `sub_type` = ~p">>).

%% 2. 个人日志
-define(SQL_SAVE_SAKURA_PERSON_LOG, <<"replace into sakura_person_log (`role_id`, `sub_type`, `id`, `reward`, `time`) values (~p, ~p, ~p, '~ts', ~p)">>).
-define(SQL_SELECT_SAKURA_PERSON_LOG, <<"select `id`,  `reward`, `time` from sakura_person_log where `role_id` = ~p and `sub_type` = ~p">>).
-define(SQL_DELETE_SQKURA_PERSON_LOG, <<"delete from sakura_person_log where `role_id` = ~p and `sub_type` = ~p and `id` = ~p">>).
-define(SQL_DELETE_ALL_SQKURA_PERSON_LOG, <<"delete from sakura_person_log where `sub_type` = ~p">>).

%% 商城数据
-define(SQL_SAVE_SAKURA_STORE, <<"replace into sakura_store (`role_id`, `sub_type`, `reward_id`, `times`) values (~p, ~p, ~p, ~p)">>).
-define(SQL_SELECT_SAKURA_STORE, <<"select `reward_id`, `times` from sakura_store where `role_id` = ~p and `sub_type` = ~p">>).
-define(SQL_DELETE_SQKURA_STORE, <<"delete from sakura_store where `sub_type` = ~p">>).