//
//  PlayerVM.swift
//  DouShouQiIOS
//
//  Created by Pierre FERREIRA on 03/06/2024.
//

import Foundation
import DouShouQiModel

class PlayerVM : ObservableObject, Identifiable {
    @Published var player : Player
    @Published var data : Player.Data
    @Published var isEditing : Bool
    
    public init(with player: Player) {
        self.player = player
        self.data = player.data
        self.isEditing = false
    }

    func onEditing(){
        self.data = player.data
        self.isEditing = true
    }
    
    func onEdited(isCanceled cancel : Bool = false){
        if !cancel {
            //save
            player.update(from: data)
        }
        isEditing.toggle()
    }
}
