package com.example.furumi_android.domain.repository

import com.example.furumi_android.domain.model.ArtistPage
import com.example.furumi_android.domain.model.ArtistDetail
import com.example.furumi_android.domain.model.ConnectedCommand
import com.example.furumi_android.domain.model.ConnectedDevicesState
import com.example.furumi_android.domain.model.ConnectedJamUser
import com.example.furumi_android.domain.model.ConnectedPlaybackState
import com.example.furumi_android.domain.model.ListeningHistoryPage
import com.example.furumi_android.domain.model.PlaylistCard
import com.example.furumi_android.domain.model.PlaylistDetail
import com.example.furumi_android.domain.model.ReleaseDetail
import com.example.furumi_android.domain.model.SearchResults
import com.example.furumi_android.domain.model.TrackCard

interface PlayerRepository {
    suspend fun getArtists(
        page: Int = 1,
        limit: Int = 60,
        mine: Boolean = false
    ): Result<ArtistPage>

    suspend fun getArtistDetail(artistId: Long): Result<ArtistDetail>

    suspend fun getReleaseDetail(releaseId: Long): Result<ReleaseDetail>

    suspend fun search(query: String, limit: Int = 20): Result<SearchResults>

    suspend fun getListeningHistory(page: Int = 1, limit: Int = 20): Result<ListeningHistoryPage>

    suspend fun toggleLike(trackId: Long): Result<Boolean>

    suspend fun getLikedTrackIds(): Result<Set<Long>>

    suspend fun recordListeningHistory(
        trackId: Long,
        startedAt: Long,
        durationListened: Int,
        completed: Boolean
    ): Result<Unit>

    suspend fun getPlaylists(): Result<List<PlaylistCard>>

    suspend fun getPlaylistDetail(playlistId: Long): Result<PlaylistDetail>

    suspend fun addTracksToPlaylist(playlistId: Long, trackIds: List<Long>): Result<Unit>

    suspend fun shareTrack(trackId: Long, title: String): Result<String>

    suspend fun pollConnectedDevice(
        playbackState: ConnectedPlaybackState?,
        currentJamId: String? = null
    ): Result<Pair<ConnectedDevicesState, List<ConnectedCommand>>>

    suspend fun setActiveDevice(deviceId: String): Result<ConnectedDevicesState>

    suspend fun sendConnectedDeviceCommand(
        targetDeviceId: String?,
        jamId: String?,
        command: String,
        payload: ConnectedPlaybackState? = null,
        tracks: List<TrackCard> = emptyList(),
        index: Int? = null,
        time: Double? = null,
        volume: Double? = null,
        shuffle: Boolean? = null,
        repeatMode: String? = null,
        fromIndex: Int? = null,
        toIndex: Int? = null
    ): Result<Unit>

    suspend fun createJam(): Result<ConnectedDevicesState>

    suspend fun joinJam(jamId: String): Result<ConnectedDevicesState>

    suspend fun leaveJam(jamId: String): Result<ConnectedDevicesState>

    suspend fun searchJamUsers(query: String, limit: Int = 10): Result<List<ConnectedJamUser>>

    suspend fun inviteToJam(jamId: String, inviteeUserIds: List<Long>): Result<ConnectedDevicesState>
}
