/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package com.runicgateway.app.data.api.fake

import com.runicgateway.app.data.api.PlayerShardApi
import com.runicgateway.app.data.api.dto.CharProfileDto
import com.runicgateway.app.data.api.dto.CreateGameAccountRequest
import com.runicgateway.app.data.api.dto.PlayerHouseDto
import com.runicgateway.app.data.api.dto.RosterDto
import com.runicgateway.app.data.api.dto.ShardLinkDto
import com.runicgateway.app.data.api.dto.ShardLinkRequest
import com.runicgateway.app.data.api.dto.ShardLinkResultDto
import com.runicgateway.app.data.api.dto.VendorSaleDto
import com.runicgateway.app.data.api.dto.VendorSnapshotDto

/**
 * A configurable fake of [PlayerShardApi] for the player self-service repository /
 * ViewModel tests. Set the relevant `var`; set [error] to throw from every call
 * (drives the `503 shard offline` / `403 not-linked` / network paths).
 */
class FakePlayerShardApi : PlayerShardApi {

    var error: Throwable? = null

    var linkResult: ShardLinkResultDto = ShardLinkResultDto()
    var accounts: List<ShardLinkDto> = emptyList()
    var roster: RosterDto = RosterDto()
    var char: CharProfileDto = CharProfileDto()
    var vendors: VendorSnapshotDto = VendorSnapshotDto()
    var sales: List<VendorSaleDto> = emptyList()
    var houses: List<PlayerHouseDto> = emptyList()

    private fun <T> reply(value: T): T {
        error?.let { throw it }
        return value
    }

    override suspend fun link(body: ShardLinkRequest): ShardLinkResultDto = reply(linkResult)
    override suspend fun createAccount(body: CreateGameAccountRequest): ShardLinkResultDto = reply(linkResult)
    override suspend fun accounts(): List<ShardLinkDto> = reply(accounts)
    override suspend fun roster(account: String): RosterDto = reply(roster)
    override suspend fun char(serial: String): CharProfileDto = reply(char)
    override suspend fun vendors(account: String): VendorSnapshotDto = reply(vendors)
    override suspend fun sales(): List<VendorSaleDto> = reply(sales)
    override suspend fun houses(): List<PlayerHouseDto> = reply(houses)
}
