%% ---------------------------------------------------------------------------
%% @doc data_guild_m.erl(data_guild_manual)

%% @author  hjh
%% @email  hejiahua@163.com
%% @since  2016-12-15
%% @deprecated 手动配置
%% ---------------------------------------------------------------------------
-module(data_guild_m).
-export([]).

-compile(export_all).

-include("guild.hrl").
-include("common.hrl").
-include("def_goods.hrl").
get_config(T) ->
    F = fun() ->
        case T of
            % 捐献日志长度
            donate_log_max_len -> 20;
            % 其他成员能被自动任命会长的最长离线时间
            auto_to_chief_max_offline_time_lim -> 259200; % 86400*3
            % 公告每周免费修改次数
            free_modify_times -> 10;
            % 修改公告花费的元宝
            modify_announce_cost_gold -> 0;
            _ -> false
        end
    end,
    case data_guild:get(T) of
        false -> F();
        Val -> Val
    end.

%% 获得职位的排序大小
get_position_sort(?POS_NORMAL) -> 0;
get_position_sort(?POS_ELITE) -> 1;
get_position_sort(?POS_DIRECTOR) -> 2;
get_position_sort(?POS_DUPTY_CHIEF) -> 3;
get_position_sort(?POS_CHIEF) -> 4;
get_position_sort(_) -> 0.

% %% 获得最大职位(删公会)
% get_max_position_sort(Position, SecPosition) ->
%     PositionNo = get_position_sort(Position),
%     SecPositionNo = get_position_sort(SecPosition),
%     max(PositionNo, SecPositionNo).

%% 获得职位的排名(用于操作低职位的权限等),领袖部分功能需要特殊处理
get_position_no(?POS_NORMAL) -> 0;
get_position_no(?POS_ELITE) -> 1;
get_position_no(?POS_DIRECTOR) -> 2;
get_position_no(?POS_DUPTY_CHIEF) -> 3;
get_position_no(?POS_CHIEF) -> 4;
get_position_no(?POS_AGENT) -> 4;
get_position_no(_) -> 0.

% %% 获得最大职位的排名
% get_max_position_no(Position, SecPosition) ->
%     PositionNo = get_position_no(Position),
%     SecPositionNo = get_position_no(SecPosition),
%     max(PositionNo, SecPositionNo).

% %% 获得最大职位
% get_max_position(Position, SecPosition) ->
%     PositionNo = get_position_no(Position),
%     SecPositionNo = get_position_no(SecPosition),
%     case PositionNo > SecPositionNo of
%         true -> Position;
%         false -> SecPosition
%     end.

%% 本职位是否能任命
is_enable_appoint_position(Position) ->
    EnableAppointList = [?POS_CHIEF],
    lists:member(Position, EnableAppointList).

%% 获得职位名字
get_position_name(_Position, PositionName, _Sex) when length(PositionName) > 0 -> PositionName;
get_position_name(_, _, _) -> "".

get_position_name(Position, _Sex) ->
    case data_guild:get_guild_pos(Position) of
        [] -> PositionName = "";
        #base_guild_pos{name = PositionName} -> ok
    end,
    PositionName.

%% 获取公会成员上限
get_guild_member_capacity(GuildLv) ->
    case data_guild:get_guild_lv(GuildLv) of
        #base_guild_lv{member_capacity = MemberCapacity} -> MemberCapacity;
        _ -> get_config(member_capacity)
    end.

%% 获取公会升级的邮件内容
get_upgrade_mail_content(_GuildLv) ->
   "shengji".

%% 获取公会职位的人数上限
get_position_max_num(GuildLv, Position) ->
    case data_guild:get_guild_lv(GuildLv) of
        #base_guild_lv{member_capacity=MaxNum, pos_list=PositionList} ->
            case lists:keyfind(Position, 1, PositionList) of
                false when Position==?POS_NORMAL ->
                    lists:foldl(fun({_,PosNum}, N)-> max(N-PosNum, 0) end, MaxNum, PositionList);
                {_,Num}-> Num;
                _ -> 0
            end;
        _ ->
            case Position of
                ?POS_CHIEF ->           1;
                ?POS_DUPTY_CHIEF ->     1;
                ?POS_DIRECTOR ->        1;
                ?POS_ELITE ->           1;
                ?POS_NORMAL ->         1;
                _ ->                    0
            end
    end.
    % case data_guild:get_guild_pos_cfg(Position) of
    %     #guild_pos_cfg{num = Num} -> Num;
    %     _ ->
    %         case Position of
    %             ?POS_CHIEF ->           1;
    %             ?POS_DUPTY_CHIEF ->     1;
    %             ?POS_NORMAL ->         99999;
    %             _ ->                    0
    %         end
    % end.

%% 领取工资的职位
get_salary_postion() ->
    EnableAppointList = [?POS_CHIEF, ?POS_DUPTY_CHIEF, ?POS_DIRECTOR, ?POS_ELITE],
    EnableAppointList.
