//
//  ViewController.m
//  ATM
//
//  David J. Malan
//  Harvard University
//  malan@harvard.edu
//
//  Simulates an ATM (that only accepts deposits).
//

#import "ViewController.h"

@implementation ViewController

@synthesize account=_account;
@synthesize amount=_amount;
@synthesize balanceLabel=_balanceLabel;
@synthesize depositLabel=_depositLabel;

- (IBAction)clear:(id)sender
{
    // clear input
    self.amount = 0;
    [self show];
}

- (IBAction)deposit:(id)sender
{
    // deposit amount
    self.account.balance += self.amount;
    
    // clear input
    self.amount = 0;
    [self show];
}

- (IBAction)digit:(id)sender
{
    // append digit to amount
    UIButton *b = (UIButton *)sender;
    self.amount = self.amount * 10 + b.tag;
    [self show];
}

- (void)show
{
    // show balance
    self.balanceLabel.text = [NSString stringWithFormat:@"$%llu", self.account.balance];
    
    // show input
    self.depositLabel.text = [NSString stringWithFormat:@"$%llu", self.amount];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)viewDidLoad
{
    // create account
    self.account = [[Account alloc] init];
    [self show];
}

@end
