import 'package:flutter/material.dart';

class Account {
  String nameOwner, nameBank, number;

  Account(this.nameOwner, this.nameBank, this.number);
}

class PortfolioProduct {
  String? name, type;
  double? yield;
  double? priceUnit, funds, totalPercent, totalUnit;

  PortfolioProduct({this.name, this.type, this.yield, this.priceUnit, this.funds, this.totalPercent = 1, this.totalUnit});
}

class RedeemProductViewModel extends ChangeNotifier {
  static Account currentAccount = Account('Muhamad Rosyidin', 'BRI', '902139012324');
  static PortfolioProduct currentProduct =
    PortfolioProduct(
      name: 'Gemilang Dana Kas Maxima',
      type: '',
      yield: 8.17,
      priceUnit: 2600.79,
      funds: 6300000,
      totalUnit: 25
  );

  static double? amount;
  static double? unit;
  Account? selectedAccount;

  Account get getCurrentAccount => currentAccount;
  PortfolioProduct get getCurrentProduct => currentProduct;
  double? get getAmount => amount;
  double? get getUnit => unit;

  bool isAgree = false;

  void setCurrentAcc(Account account) {
    currentAccount = account;
    notifyListeners();
  }

  void setSelectedAcc(Account account){
    selectedAccount = account;
    notifyListeners();
  }

  void setAmount(double amount) {
    amount = amount;
    unit = (amount / currentProduct.priceUnit!);
    notifyListeners();
  }

  void setUnit(double value){
    unit = currentProduct.totalUnit! * value;
    amount = unit! * currentProduct.priceUnit!;
    notifyListeners();
  }

  void setProduct(PortfolioProduct product) {
    currentProduct = product;
    amount = product.priceUnit! * (product.totalUnit! / 2.0);
    unit = (product.totalUnit! / 2.0);
    notifyListeners();
  }

  void setAgree() {
    isAgree = !isAgree;
    notifyListeners();
  }
}