from django.contrib.auth.models import User as django_user
from django.db import models

# Create your models here.
from django.utils import timezone

from financial.consts import TransactionPaymentType
from utils.model_fields import RestrictedFileField


class ExchangeRate(models.Model):
    create_time = models.DateTimeField(default=timezone.now)
    creator = models.ForeignKey(django_user, on_delete=models.SET_NULL, null=True)
    name = models.CharField(max_length=100, null=True, blank=True)
    best_buy = models.CharField(max_length=100, null=True, blank=True)
    best_sell = models.CharField(max_length=100, null=True, blank=True)
    day_change = models.CharField(max_length=100, null=True, blank=True)
    day_close = models.CharField(max_length=100, null=True, blank=True)
    day_high = models.CharField(max_length=100, null=True, blank=True)
    day_low = models.CharField(max_length=100, null=True, blank=True)
    day_open = models.CharField(max_length=100, null=True, blank=True)
    is_closed = models.BooleanField(default=False, null=True, blank=True)
    latest = models.CharField(max_length=100, null=True, blank=True)
    mark = models.CharField(max_length=100, null=True, blank=True)


class Transaction(models.Model):
    create_time = models.DateTimeField(default=timezone.now)
    creator = models.ForeignKey(django_user, on_delete=models.SET_NULL, null=True)
    transaction_date = models.DateTimeField(default=timezone.now)
    description = models.TextField(null=True, blank=True)
    payment_type = models.CharField(max_length=255, choices=TransactionPaymentType, null=True, blank=True)
    cashier = models.ForeignKey('financial.Cashier', on_delete=models.SET_NULL, null=True)  # صندوق
    beneficiary = models.CharField(max_length=255, null=True, blank=True)  # ذینفع
    payment = models.IntegerField(default=0, null=True, blank=True)  # پرداخت
    receipt = models.IntegerField(default=0, null=True, blank=True)  # دریافت
    usdt_payment = models.FloatField(default=0)
    usdt_receipt = models.FloatField(default=0)
    accounting_headings = models.ForeignKey(
        'financial.AccountingHeadings', on_delete=models.SET_NULL, null=True)  # سرفصل‌های حسابداری
    cost_center = models.ForeignKey('financial.CostCenter', on_delete=models.SET_NULL, null=True)  # مرکز هزینه
    factor_image = RestrictedFileField(
        upload_to='factors/', blank=True, null=True,
        content_types=['application/pdf', 'video/mp4', 'audio/mpeg', 'image/jpeg', 'image/png', 'image/jpg'],
        max_upload_size=5242880)
    archived = models.BooleanField(default=False)


class Cashier(models.Model):
    create_time = models.DateTimeField(default=timezone.now)
    name = models.CharField(max_length=255, null=True, blank=True)
    currency = models.CharField(max_length=255, choices=TransactionPaymentType)


class AccountingHeadings(models.Model):
    create_time = models.DateTimeField(default=timezone.now)
    name = models.CharField(max_length=255, null=True, blank=True)


class CostCenter(models.Model):
    create_time = models.DateTimeField(default=timezone.now)
    name = models.CharField(max_length=255, null=True, blank=True)
