"""Defines some model to test the hashable app."""

from django.db import models

from ...hashers import md5_hash, with_default
from ...models import Hashable


class Model1(Hashable):
    """Model to test that a non-nullable field can be used with the default configuration."""

    non_nullable_file = models.FileField()
    non_nullable_hash = models.CharField(max_length=36)

    hashable_fields = [
        ('non_nullable_file', 'non_nullable_hash'),
    ]


class Model2(Hashable):
    """Model to test that nullable file field cannot use the default configuration.

    Indeed, the default ``md5_hash`` function will fail when trying to access the content
    of a file field that is not set.

    """

    nullable_file = models.FileField(blank=True, null=True)
    nullable_hash = models.CharField(max_length=36, blank=True, null=True)

    hashable_fields = [
        ('nullable_file', 'nullable_hash'),
    ]


class Model3(Hashable):
    """Model to test the with_default "decorator"."""

    default_hash_function = with_default('default', md5_hash)

    nullable_file1 = models.FileField(blank=True, null=True)
    nullable_hash1 = models.CharField(max_length=36, blank=True, null=True)

    nullable_file2 = models.FileField(blank=True, null=True)
    nullable_hash2 = models.CharField(max_length=36, blank=True, null=True)

    nullable_file3 = models.FileField(blank=True, null=True)
    nullable_hash3 = models.CharField(max_length=36, blank=True, null=True)

    hashable_fields = [
        ('nullable_file1', 'nullable_hash1'),
        ('nullable_file2', 'nullable_hash2', with_default('foo')),
        ('nullable_file3', 'nullable_hash3', with_default('bar', md5_hash, [ValueError])),
    ]


class Model4(Hashable):
    """Model to test default hash methods."""

    file1 = models.FileField()
    hash1 = models.CharField(max_length=36)

    file2 = models.FileField()
    hash2 = models.CharField(max_length=36)

    hashable_fields = [
        ('file1', 'hash1'),
        ('file2', 'hash2'),
    ]

    default_compute_hash_method = 'default_compute_hash'
    compute_hash_method_pattern = 'sepcific_compute_hash_%(field_name)s_%(hash_field_name)s'

    def default_compute_hash(self, field_name, *args, **kwargs):
        """Default method"""
        return 'default hash for %s' % field_name

    def sepcific_compute_hash_file2_hash2(self, field_name, *args, **kwargs):
        """Specific method"""
        return 'specific hash for %s' % field_name
