import Foundation
import CoreData

@objc(Asset)
public class Asset: NSManagedObject, Identifiable {
    @nonobjc public class func fetchRequest() -> NSFetchRequest<Asset> {
        return NSFetchRequest<Asset>(entityName: "Asset")
    }

    @NSManaged public var id: UUID
    @NSManaged public var name: String
    @NSManaged public var symbol: String?
    @NSManaged public var type: String
    @NSManaged public var currency: String?
    @NSManaged public var createdAt: Date
    @NSManaged public var sources: NSSet?

    public override func awakeFromInsert() {
        super.awakeFromInsert()
        id = UUID()
        createdAt = Date()
        name = ""
        type = AssetType.stock.rawValue
    }
}

enum AssetType: String, CaseIterable, Identifiable {
    case stock
    case etf
    case crypto
    case fund
    case cash
    case realEstate
    case other

    var id: String { rawValue }

    var displayName: String {
        switch self {
        case .stock: return "Stock"
        case .etf: return "ETF"
        case .crypto: return "Crypto"
        case .fund: return "Fund"
        case .cash: return "Cash"
        case .realEstate: return "Real Estate"
        case .other: return "Other"
        }
    }
}

