from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Income(models.Model):
    source = models.CharField(max_length=255)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    date = models.DateField()

    def __str__(self):
        return f"{self.source} - {self.amount}"

class Expense(models.Model):
    title = models.CharField(max_length=255)
    category = models.CharField(max_length=100)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    date = models.DateField()
    description = models.TextField(blank=True, null=True)

    def __str__(self):
        return f"{self.title} - {self.amount}"

class Category(models.Model):
    name = models.CharField(max_length=50, unique=True)

    def __str__(self):
        return self.name

class UserSettings(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='settings')
    monthly_budget = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    yearly_budget = models.DecimalField(max_digits=12, decimal_places=2, default=0)
    preferred_currency = models.CharField(max_length=10, default='USD')

    def __str__(self):
        return f"Settings for {self.user.username}"
