package com.fp.frontend.webservices.impl;

import javax.jws.WebService;

import com.fp.common.logger.APPLogger;
import com.fp.dto.Request;
import com.fp.dto.Response;
import com.fp.frontend.helper.CallerHelper;
import com.fp.frontend.webservices.ArmaService;
import com.fp.persistence.parmas.dto.ws.ArmaDto;

@WebService(endpointInterface = "com.fp.frontend.webservices.ArmaService")
public class ArmaServiceImpl implements ArmaService {

    @Override
    public ArmaDto obtenerArmaId(String carma) {
        // TODO Auto-generated method stub
        ArmaDto armaDto = null;
        try {
            CallerHelper callerHelper = new CallerHelper();
            Request request = callerHelper.getRequest();
            request.setCompany(1);
            request.put("queryalias", "ARMASWS");
            request.put("codigoarma", carma);
            Response response = callerHelper.executeQuery(request);
            if (response.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
                armaDto = (ArmaDto) response.get("ARMASWS");
            }
            return armaDto;
        } catch (Throwable e) {
            return null;
        }
    }

    @Override
    public String vinculaTagArma(String codigoarma, String codigotag) {
        String respuesta = "0";
        try {
            CallerHelper callerHelper = new CallerHelper();
            Request request = callerHelper.getRequest();
            request.setCompany(1);
            request.put("CODIGOARMA", codigoarma);
            request.put("CODIGOTAG", codigotag);
            request.setTransactionModule("30");
            request.setTransactionCode(9999);
            request.setTransactionVersion(1);
            Response response = callerHelper.executeSave(request);
            if (response.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
                respuesta = (String) response.get("RESPONSESTATUS");
            }
        } catch (Throwable e) {
            respuesta = "2";
            APPLogger.getLogger().error(e.getMessage(), e);
        }
        return respuesta;
    }

    @Override
    public String desvinculaTagArma(String codigoarma, String codigotag) {
        String respuesta = "0";
        try {
            CallerHelper callerHelper = new CallerHelper();
            Request request = callerHelper.getRequest();
            request.setCompany(1);
            request.put("CODIGOARMA", codigoarma);
            request.put("CODIGOTAG", codigotag);
            request.setTransactionModule("30");
            request.setTransactionCode(9998);
            request.setTransactionVersion(1);
            Response response = callerHelper.executeSave(request);
            if (response.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
                respuesta = (String) response.get("RESPONSESTATUS");
            }
        } catch (Throwable e) {
            respuesta = "2";
            APPLogger.getLogger().error(e.getMessage(), e);
        }
        return respuesta;
    }

    @Override
    public ArmaDto obtenerArmaPorTag(String codigotag) {
        // TODO Auto-generated method stub
        ArmaDto armaDto = null;
        try {
            CallerHelper callerHelper = new CallerHelper();
            Request request = callerHelper.getRequest();
            request.setCompany(1);
            request.put("queryalias", "ARMASWS");
            request.put("codigotag", codigotag);
            Response response = callerHelper.executeQuery(request);
            if (response.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
                armaDto = (ArmaDto) response.get("ARMASWS");
            }
            return armaDto;
        } catch (Throwable e) {
            return null;
        }
    }

}
