-module(the_duke).
-behaviour(gen_sovereign).
-export([rule/0]).

start(Pars) -> 
    io:format("The duke is dead. Long live the duke ~p!~n",[Pars]),
    gen_sovereign:start_link({local, ?MODULE}, ?MODULE, [Pars], []).

stop() ->
    io:format("I'm a powerful duke, you can't stope my rule!~n"),
    gen_sovereign:cast(?MODULE, revolt).

coronation([Pars]) ->
    io:format("I am the ruler of duchy ~p!~n",[Pars]),
    process_flag(trap_exit, true),
    {ok, coronated}.

handle_call_to_arms(Message, From, State) when is_ally(From) -> 
    {accept, raise_grand_army(), State};

handle_call_to_arms(Message, king, State) ->
    {decline, start_revolt(), State}.
    
handle_info({vassal_doesnt_pay_taxes, Vassal}, State) ->
    {send_to_prison, Vassal, State}.