package ttk.commands;

import device.Pinpad;
import tlv.TlvItem;

public class Service extends CommandBase {
    public static enum CommandType{
        TTK_OPERATION_TOTALS       ('2'),
        TTK_OPERATION_TEST_SERVER  ('3'),
        TTK_OPERATION_TEST_HOST    ('4'),
        TTK_OPERATION_FULL_REPORT  ('5'),
        TTK_OPERATION_BRIEF_REPORT ('6'),
        TTK_OPERATION_HELP         ('H'),
        TTK_OPERATION_FLUSH_KEYS   ('F'),
        TTK_OPERATION_REMLOAD      ('R'),
        TTK_OPERATION_READ_CONFIG  ('r'),
        TTK_OPERATION_WRITE_CONFIG ('w'),
        TTK_OPERATION_MONIT        ('M'),
        TTK_OPERATION_SIGN         ('S'),
        TTK_OPERATION_SPEC_READ    ('Z'),
        TTK_OPERATION_SHOW_INPUT   ('I'),
        TTK_OPERATION_MERCH_CHEQUE ('V'),
        TTK_OPERATION_SUSPEND_TRX  ('D'),
        TTK_OPERATION_COMMIT_TRX   ('E'),
        TTK_OPERATION_ROLLBACK_TRX ('A'),
        TTK_OPERATION_STATUS_REQ   ('B'),
        TTK_OPERATION_CALL_MENU    ('C'),
        TTK_OPERATION_OPEN_READER  ('o'),
        TTK_OPERATION_TEST_READER  ('t'),
        TTK_OPERATION_CLOSE_READER ('e');
        private final char operTypeChar;

        CommandType(char operTypeChar) {
            this.operTypeChar = operTypeChar;
        }

        public char getOperTypeChar() {
            return operTypeChar;
        }
    }
    private CommandType operType;

    public Service(Pinpad pinpad, CommandType operType){
        super(pinpad);
        this.operType = operType;
    }

    protected void prepare(){
        try {
            context.add(new TlvItem(tlv.Tag.findTag("TAG_TTK_CLIENT_MID"), "SRV"));
            context.add(new TlvItem(tlv.Tag.findTag("TAG_TTK_OPER_TYPE"), new byte[] {(byte)this.operType.getOperTypeChar()}));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
