from django.db import models
import django.utils.timezone
from random import randint
from django.contrib.auth.models import User


'''
Не дописаны репры
Добавить историю операций
'''


class Account(models.Model):
    number = models.CharField(max_length=32,
                              default=str(randint(100000000, 999999999)),
                              unique=True)
    client = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
    balance = models.IntegerField(default=0)
    date_open = models.DateTimeField(default=django.utils.timezone.now)

    def __repr__(self):
        return '<Object Account: id = {}, number = {}, balance = {}>'.format(self.id,
                                                                             self.number,
                                                                             self.balance)


'''class DepositType(models.Model):
    title = models.CharField(max_length=32, unique=True)
    percent = models.IntegerField()

    def __repr__(self):
        return '<Object DepositType: id = {}, title = {}, percent = {}>'.format(self.id,
                                                                                self.title,
                                                                                self.percent)


class CreditType(models.Model):
    title = models.CharField(max_length=32, unique=True)
    percent = models.IntegerField()

    def __repr__(self):
        return '<Object DepositType: id = {}, title = {}, percent = {}>'.format(self.id,
                                                                                self.title,
                                                                                self.percent)'''


class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    balance = models.IntegerField(default=2000)


class Credit(models.Model):
    # type = models.ForeignKey(CreditType, on_delete=models.CASCADE)
    date_open = models.DateTimeField(default=django.utils.timezone.now)
    start_sum = models.IntegerField()
    loan = models.IntegerField()
    owner = models.IntegerField(default=0)

    def __repr__(self):
        return '<Object Account: id = {}>'.format(self.id)


class Deposit(models.Model):
    date_open = models.DateTimeField(default=django.utils.timezone.now)
    start_sum = models.IntegerField()
    loan = models.IntegerField()
    owner = models.IntegerField(default=0)
