// Copyright (C) 2026 Jason M. Schwefel. All Rights Reserved.
package com.coldboreballisticsllc.scopedope.domain.repository

import kotlinx.coroutines.flow.Flow
import com.coldboreballisticsllc.scopedope.domain.model.AmmoLoad

/** Thrown by [AmmoRepository.addUserAmmo] when (caliber, name) already exists. */
class DuplicateAmmoException(name: String) : Exception("\"$name\" already exists for this caliber")

interface AmmoRepository {
    /** All entries (built-in + user) as a live stream, grouped caliber/name order. */
    fun observeAll(): Flow<List<AmmoLoad>>

    /** Distinct calibers from both databases. */
    suspend fun getCalibers(): List<String>

    /** All entries for a specific caliber. */
    suspend fun getByCaliber(caliber: String): List<AmmoLoad>

    /** Search by name or caliber substring. */
    suspend fun search(query: String): List<AmmoLoad>

    /** User DB only — create a new custom entry. */
    suspend fun addUserAmmo(load: AmmoLoad)

    /** User DB only — update an existing custom entry. */
    suspend fun updateUserAmmo(load: AmmoLoad)

    /** User DB only — delete a custom entry. */
    suspend fun deleteUserAmmo(id: Int)
}
