package rest;

import tm.CompaniasTeatroCM;
import tm.FuncionesCM;
import vos.CompaniasTeatroVos;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;

/**
 *
 */
@Path( "companiasteatro" )
@Produces({MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON})
public class CompaniasTeatroServices extends Services
{
    @GET
    public Response getCompaniasTeatros( )
    {
        CompaniasTeatroCM cm = new CompaniasTeatroCM( getPath( ) );
        try
        {
            ArrayList<CompaniasTeatroVos> list = cm.getCompaniasTeatrosLocal();
            return Response.status( 200 ).entity( list ).build( );
        }
        catch( Exception e )
        {
            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );
        }
    }

    @GET
    @Path( "{id}/{tipoId}" )
    public Response getCompaniasTeatro( @PathParam( "id" ) Long id, @PathParam("tipoId") String tipoId)
    {
        CompaniasTeatroCM cm = new CompaniasTeatroCM( getPath( ) );
        try
        {
            CompaniasTeatroVos dao = cm.getCompaniasTeatroLocal(id, tipoId);
            return Response.status( 200 ).entity( dao ).build( );
        }
        catch( Exception e )
        {
            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );
        }
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response createCompaniasTeatro( CompaniasTeatroVos object, @HeaderParam("id") Long id, @HeaderParam("tipo") String tipo )
    {
        CompaniasTeatroCM cm = new CompaniasTeatroCM( getPath( ) );
        try
        {
            cm.createCompaniasTeatroLocal(object,id,tipo);
        }
        catch( Exception e )
        {
            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );
        }
        return Response.status( 200 ).entity( object ).build( );
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response updateCompaniasTeatro( CompaniasTeatroVos object )
    {
        CompaniasTeatroCM cm = new CompaniasTeatroCM( getPath( ));
        try
        {
            cm.updateCompaniasTeatroLocal(object);
            return Response.status( 200 ).entity( object ).build( );
        }
        catch( Exception e )
        {
            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );
        }
    }

    @DELETE
    @Path( "{id}/{tipoId}" )
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response deleteCompaniasTeatro( @PathParam( "id" ) Long id, @PathParam("tipoId") String tipoId)
    {
        CompaniasTeatroCM cm = new CompaniasTeatroCM( getPath( ) );
        try
        {
            cm.deleteCompaniasTeatro(id, tipoId);
            return Response.status( 200 ).build( );
        }
        catch( Exception e )
        {
            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );
        }
    }

    //todo: req 16
    @DELETE
    @Path( "{id}/{tipoId}" )
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response retirarCompaniaTeatro( @PathParam( "id" ) Long id, @PathParam("tipoId") String tipoId)
    {
        CompaniasTeatroCM cm = new CompaniasTeatroCM( getPath( ) );

        FuncionesCM cm2 = new FuncionesCM( getPath( ) );

        try
        {
            ArrayList<Long> funciones = cm.traerFuncionesPorCompaniaLocal(id, tipoId);

            for(Long idFuncion: funciones)
            {
                cm2.cancelarFuncionLocal(idFuncion);
            }
            cm.deleteCompaniasTeatro(id, tipoId);
            return Response.status( 200 ).build( );
        }
        catch( Exception e )
        {
            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );
        }
    }
}
@@ -8,16 +8,90 @@
  rest;%0A%0A
+import jms.IncompleteReplyException;%0Aimport protocolos.ProtocoloCompania;%0A
 import t
@@ -284,16 +284,39 @@
 rayList;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -4022,9 +4022,597 @@
 %7D%0A    %7D%0A
+    @DELETE%0A    @Path( %22/remote/%7Bid%7D%22 )%0A    public Response deleteCompaniaDeTeatroRemote( @PathParam( %22id%22 ) Long id, @HeaderParam(%22tipo%22) String tipo ) throws IncompleteReplyException %7B%0A        List%3CProtocoloCompania%3E list;%0A        CompaniasTeatroCM tm = new CompaniasTeatroCM( getPath( ) );%0A        try%0A        %7B%0A            list = tm.deleteCompaniaDeTeatroRemote( id,tipo );%0A        %7D%0A        catch( Exception e )%0A        %7B%0A            return Response.status( 500 ).entity( doErrorMessage( e ) ).build( );%0A        %7D%0A        return Response.status( 200 ).entity( list ).build( );%0A    %7D%0A
 %7D

kill me