import Foundation
import CoreData

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

    @NSManaged public var id: UUID
    @NSManaged public var name: String
    @NSManaged public var targetAmount: NSDecimalNumber?
    @NSManaged public var targetDate: Date?
    @NSManaged public var isActive: Bool
    @NSManaged public var createdAt: Date
    @NSManaged public var account: Account?

    public override func awakeFromInsert() {
        super.awakeFromInsert()
        id = UUID()
        createdAt = Date()
        name = ""
        isActive = true
    }
}

// MARK: - Computed Properties

extension Goal {
    var targetDecimal: Decimal {
        targetAmount?.decimalValue ?? Decimal.zero
    }
}

