/*@GET
      @Path("{mediaId}")
  	@Consumes({ MediaType.APPLICATION_JSON })
  	@Produces({ MediaType.APPLICATION_JSON })
  	public String retrieveSingleMediaAssestDetails(@PathParam("mediaId") final Long mediaId,@Context final UriInfo uriInfo) {
           context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);

           MediaAssetData mediaAssetData=this.mediaAssetReadPlatformService.retrievemediaAsset(mediaId);
           List<EnumOptionData> status = this.planReadPlatformService.retrieveNewStatus();
           List<MediaassetAttribute> data   = this.mediaAssetReadPlatformService.retrieveMediaAttributes();
           List<MediaassetAttribute> mediaFormat=this.mediaAssetReadPlatformService.retrieveMediaFormatType();
           List<MediaEnumoptionData> mediaTypeData =this.mediaAssetReadPlatformService.retrieveMediaTypeData();
           List<McodeData> mediaCategeorydata=this.mediaAssetReadPlatformService.retrieveMedaiCategory();
           List<McodeData> languageCategeory=this.mediaAssetReadPlatformService.retrieveLanguageCategeories();
           MediaAssetData assetData=new MediaAssetData(status,data,mediaFormat,mediaTypeData,mediaCategeorydata,languageCategeory);
  		final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
  		return this.toApiJsonSerializer.serialize(settings, assetData, RESPONSE_DATA_PARAMETERS);

  }*/
  @GET
  @Path("{mediaId}")
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_JSON})
  public String retrieveSingleMediaAssestDetails(
      @PathParam("mediaId") final Long mediaId, @Context final UriInfo uriInfo) {
    context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);

    MediaAssetData mediaAssetData = this.mediaAssetReadPlatformService.retrievemediaAsset(mediaId);
    List<MediaassetAttributeData> mediaassetAttributes =
        this.mediaAssetReadPlatformService.retrieveMediaassetAttributesData(mediaId);
    List<MediaLocationData> mediaLocationData =
        this.mediaAssetReadPlatformService.retrievemediaAssetLocationdata(mediaId);
    List<EnumOptionData> status = this.planReadPlatformService.retrieveNewStatus();
    List<MediaassetAttribute> data = this.mediaAssetReadPlatformService.retrieveMediaAttributes();
    List<MediaassetAttribute> mediaFormat =
        this.mediaAssetReadPlatformService.retrieveMediaFormatType();
    List<MediaEnumoptionData> mediaTypeData =
        this.mediaAssetReadPlatformService.retrieveMediaTypeData();
    List<McodeData> mediaCategeorydata = this.mediaAssetReadPlatformService.retrieveMedaiCategory();
    List<McodeData> mediaLanguageData =
        this.mediaAssetReadPlatformService.retrieveLanguageCategeories();
    List<SettlementData> settlementData = null;
    Long partnerId = mediaAssetData.getContentProvider();
    String partnerName = "";
    if (partnerId != null && partnerId > 0) {
      partnerName = mediaAssetReadPlatformService.getPartnerName(partnerId);
    }

    if (mediaAssetData != null && mediaAssetData.getMediaCategoryG().equalsIgnoreCase("Games")) {
      settlementData = this.mediaAssetReadPlatformService.retrieveSettlementData(mediaId);
    }

    MediaAssetData assetData =
        new MediaAssetData(
            mediaAssetData,
            mediaassetAttributes,
            mediaLocationData,
            status,
            data,
            mediaFormat,
            mediaTypeData,
            mediaCategeorydata,
            mediaLanguageData,
            settlementData);
    assetData.setPartnerName(partnerName);
    final ApiRequestJsonSerializationSettings settings =
        apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    return this.toApiJsonSerializer.serialize(settings, assetData, RESPONSE_DATA_PARAMETERS);
  }
  @GET
  @Path("mediaIdForGame/{id}")
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_JSON})
  public String getGameDetails(
      @Context final UriInfo uriInfo, @PathParam("id") final Long mediaAssetId) {

    context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
    MediaAssetData mediaAssetData =
        this.mediaAssetReadPlatformService.retrievemediaAsset(mediaAssetId);
    List<SettlementData> settlementData =
        this.mediaAssetReadPlatformService.retriveSettlementDetails(mediaAssetId);

    final Collection<MCodeData> mediaCategory =
        codeReadPlatformService.getCodeValue("MediaGameCategory");
    final Collection<MCodeData> mediaType = codeReadPlatformService.getCodeValue("MediaGameType");
    /*final Collection<MCodeData> mediaContentProvider = codeReadPlatformService.getCodeValue("MediaGameDescription");*/
    final Collection<MCodeData> source = codeReadPlatformService.getCodeValue("Deck Type");

    List<MCodeData> mediaContentProvider = new ArrayList<MCodeData>();

    final Collection<MCodeData> revenueHolders =
        codeReadPlatformService.getCodeValue("GameRevenueHolders");
    for (MCodeData c : revenueHolders) {
      final List<MCodeData> mcp = codeReadPlatformService.getCodeValueForGame(c.getmCodeValue());
      for (MCodeData mc : mcp) {
        mediaContentProvider.add(mc);
      }
    }
    Collection<GameMediaDetailsData> contentProviderName =
        mediaAssetReadPlatformService.retriveContentProvider();

    mediaAssetData.setSettlementData(settlementData);
    mediaAssetData.setMediaCategory(mediaCategory);
    mediaAssetData.setMediaType(mediaType);
    mediaAssetData.setMCProvider(mediaContentProvider);
    mediaAssetData.setSource(source);
    mediaAssetData.setContentProviderName(contentProviderName);

    final ApiRequestJsonSerializationSettings settings =
        apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    return this.toApiJsonSerializer.serialize(settings, mediaAssetData, RESPONSE_DATA_PARAMETERS);
  }
  // Get All Media Asset Details
  @GET
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_JSON})
  public String retrieveMediaAssestdata(
      @QueryParam("deviceId") final String deviceId,
      @QueryParam("pageNo") Long pageNum,
      @QueryParam("filterType") final String filterType,
      @Context final UriInfo uriInfo) {
    context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
    MediaDeviceData details = this.deviceReadPlatformService.retrieveDeviceDetails(deviceId);
    Long pageNo = new Long(0);
    if (pageNum == null || pageNum == 0) {
      pageNum = new Long(0);
    } else {
      pageNo = (pageNum * 10);
    }
    List<MediaAssetData> data = new ArrayList<MediaAssetData>();
    if (filterType.equalsIgnoreCase("ALL")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdata(pageNo);

      final String queryFOrPages =
          " SELECT count(0)  FROM b_media_asset m inner join b_event_detail ed on ed.media_id = m.id"
              + " inner join b_event_master em on em.id = ed.event_id  GROUP BY m.id  having  count( ed.media_id) = 1 ";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(queryFOrPages);
      for (MediaAssetData assetData : data) {

        List<MediaLocationData> locationData =
            this.mediaAssetReadPlatformService.retrievemediaAssetLocationdata(
                assetData.getMediaId());
      }

      data.add(new MediaAssetData(noOfPages, pageNum));

    } else if (filterType.equalsIgnoreCase("RELEASE")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdatabyNewRealease(pageNo);
      final String query =
          " SELECT count(0) FROM b_media_asset m INNER JOIN b_event_detail ed ON ed.media_id = m.id"
              + " INNER JOIN b_event_master em  ON em.id = ed.event_id where m.release_date <= adddate(now(),INTERVAL -3 MONTH)"
              + " group by m.id  having count(distinct ed.event_id) >=1 ";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));

    } else if (filterType.equalsIgnoreCase("RATING")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdatabyRating(pageNo);
      final String query =
          " SELECT count(0) FROM b_media_asset m INNER JOIN b_event_detail ed ON ed.media_id = m.id"
              + " INNER JOIN b_event_master em ON em.id = ed.event_id group by m.id  having count(distinct ed.event_id) >=1 ";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));
    } else if (filterType.equalsIgnoreCase("DISCOUNT")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdatabyDiscountedMovies(pageNo);
      final String query =
          " SELECT count(0) FROM b_media_asset m INNER JOIN b_event_detail ed ON ed.media_id = m.id"
              + " INNER JOIN b_event_master em  ON em.id = ed.event_id inner join  b_event_pricing ep on em.id=ep.event_id"
              + " where discount_id>=1  group by m.id  having count(distinct ed.event_id) >=1";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));
    } else if (filterType.equalsIgnoreCase("PROMOTION")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdatabyPromotionalMovies(pageNo);
      final String query =
          " SELECT count(0)  FROM b_media_asset m inner join b_event_detail ed on ed.media_id = m.id"
              + " inner join b_event_master em on em.id = ed.event_id  group by m.id  having count(distinct ed.event_id) >1 ";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));
    } else if (filterType.equalsIgnoreCase("COMING")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdatabyComingSoonMovies(pageNo);
      final String query = " SELECT count(0) FROM b_media_asset m where category_id=19 ";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));
    } else if (filterType.equalsIgnoreCase("WATCHED")) {

      data = this.mediaAssetReadPlatformService.retrievemediaAssetdatabyMostWatchedMovies(pageNo);
      final String query =
          "SELECT count(0) FROM b_media_asset m inner join b_event_detail ed on m.id=ed.media_id  inner "
              + " JOIN b_eventorder eo  ON (eo.event_id = ed.event_id)";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));
    } else {

      data =
          this.mediaAssetReadPlatformService.retrievemediaAssetdatabySearching(pageNo, filterType);
      final String query =
          "SELECT count(0) FROM b_media_asset m inner join b_event_detail ed on m.id=ed.media_id  inner "
              + " JOIN b_eventorder eo  ON (eo.event_id = ed.event_id)";
      Long noOfPages = this.mediaAssetReadPlatformService.retrieveNoofPages(query);
      data.add(new MediaAssetData(noOfPages, pageNum));
    }

    final ApiRequestJsonSerializationSettings settings =
        apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    return this.toApiJsonSerializer.serialize(settings, data, RESPONSE_DATA_PARAMETERS);
  }