using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoVideo.Nbanque
{
    /* Pour les premiers Tps (module1 et début du module2) de la vidéo, les annotations ne sont pas utilisés 
       il faut donc les mettre en commentaire */

    [Table("T_Comptes")]
    public class Compte
    {
        #region attributs 

        #endregion

        #region proprietes
      
        [Key]
        [Column("IdCompte")]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long CompteId { get; set;  }

        [Column("C_Numero")]
        [Required]
        [MaxLength(20)]
        public string Numero { get; set;  }
         
        [Column("C_Solde")]
        [DataType("Real")]
        public float Solde { get; set; }

        [Column("C_DateCreation")]
        [Required]
        public DateTime DateCreation { get; set; }

        #endregion

        #region constructeurs

        public Compte(string numero, DateTime dateCreation, float solde)
        {
            Numero = numero;
            DateCreation = dateCreation;
            Solde = solde;
          
        }

        public Compte(string numero)
        {
            Numero = numero;
            DateCreation = DateTime.Now;
            Solde = 0;
          
        }

        public Compte() : this("Undefined") { }


        public void Deconstruct(out string numero, out float solde, out DateTime dateCreation)
        {
            numero = this.Numero;
            solde = this.Solde;
            dateCreation = DateCreation;
        }

        public void Deconstruct(out string numero, out float solde)
        {
            numero = this.Numero;
            solde = this.Solde;
        }

        #endregion

        #region methodes

        public void Crediter ( float montant)
        {
            Solde += montant; 
        }

        public bool Debiter(float montant)
        {
            bool res = false;
            if (montant <= Solde)
            {
                Solde -= montant;
                res = true;
            }
            return res;
        }

        public override string ToString() => $"Numero : {Numero} Solde : {Solde} DateCreation : {DateCreation}";

        #endregion
      
    }
}
