﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BudgetExercise.Models;
using System.ComponentModel.DataAnnotations;

namespace BudgetExercise.ViewModels
{
    public class PlannedCredit
    {
        public int Id { get; set; }

        [Required]
        public string Note { get; set; }

        [Required]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:C}")]
        public decimal Amount { get; set; }

        [Required]
        public int BudgetId { get; set; }

        public PlannedCredit() { }

        public PlannedCredit(int budgetId)
        {
            BudgetId = budgetId;
        }

        public PlannedCredit(LineItem lineItem)
        {
            if (!lineItem.IsPlanned || !lineItem.IsCredit)
                throw new InvalidCastException();

            Id = lineItem.Id;
            Note = lineItem.Note;
            Amount = lineItem.Amount;
            BudgetId = lineItem.BudgetId;
        }
    }
}