Coverage Summary for Class: BazaarUrlsKt (com.galarzaa.tibiakt.core.section.charactertrade.urls)

Class Class, % Method, % Branch, % Line, % Instruction, %
BazaarUrlsKt 100% (1/1) 75% (3/4) 56.2% (9/16) 96.3% (26/27) 88.6% (203/229)


 /*
  * Copyright © 2025 Allan Galarza
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.galarzaa.tibiakt.core.section.charactertrade.urls
 
 import com.galarzaa.tibiakt.core.domain.world.PvpType
 import com.galarzaa.tibiakt.core.net.tibiaUrl
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionBattlEyeFilter
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionOrderBy
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionOrderDirection
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionPagesType
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionSearchType
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionSkillFilter
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.AuctionVocationFilter
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.BazaarFilters
 import com.galarzaa.tibiakt.core.section.charactertrade.bazaar.model.BazaarType
 
 /**
  * URL to the character bazaar.
  *
  * @param type Whether to show current auctions or the auction history.
  */
 public fun bazaarUrl(type: BazaarType = BazaarType.CURRENT, filters: BazaarFilters? = null, page: Int = 1): String =
     tibiaUrl(
         "charactertrade",
         type.subtopic,
         "currentpage" to page,
         *filters.queryParams()
     )
 
 
 private fun BazaarFilters?.queryParams(): Array<Pair<String, Any?>> {
     return if (this != null) arrayOf(
         "filter_world" to world,
         AuctionVocationFilter.QUERY_PARAM to vocation?.value,
         "filter_levelrangefrom" to minimumLevel,
         "filter_levelrangeto" to maximumLevel,
         PvpType.QUERY_PARAM_BAZAAR to pvpType?.bazaarFilterValue,
         AuctionBattlEyeFilter.QUERY_PARAM to battlEyeType?.value,
         AuctionSkillFilter.QUERY_PARAM to skill?.value,
         "filter_skillrangefrom" to minimumSkillLevel,
         "filter_skillrangeto" to maximumSkillLevel,
         AuctionOrderBy.QUERY_PARAM to orderBy?.value,
         AuctionOrderDirection.QUERY_PARAM to orderDirection?.value,
         "searchstring" to searchString,
         AuctionSearchType.queryParam to searchType?.value,
     ) else emptyArray()
 }
 
 /**
  * URL to a specific auction.
  */
 public fun auctionUrl(auctionId: Int): String =
     tibiaUrl(
         "charactertrade",
         "currentcharactertrades",
         "page" to "details",
         "auctionid" to auctionId
     )
 
 
 /** URL to the endpoint to get additional elements for an auction. */
 public fun auctionCharacterDetailsUrl(auctionId: Int, type: AuctionPagesType, page: Int): String =
     "https://www.tibia.com/websiteservices/handle_charactertrades.php?auctionid=$auctionId&type=${type.typeId}&currentpage=$page"