import datetime
from django.utils import timezone
from factory import SubFactory
from factory.fuzzy import FuzzyText, FuzzyInteger, FuzzyDateTime, FuzzyDate, FuzzyDecimal, FuzzyChoice
from factory.django import DjangoModelFactory

from companies.factories import CompanyFactory

from products.models import Product


FAKE_CATEGORIES = (
    ('categoria-1'),
    ('categoria-2'),
    ('categoria-3'),
    ('categoria-4'),
    ('categoria-5'),
    ('categoria-6'),
)

class ProductFactory(DjangoModelFactory):


    company = SubFactory(CompanyFactory)
    sku = FuzzyText(prefix='SKU_', length=10)
    name = FuzzyText(prefix='NAME_', length=10)
    description = FuzzyText(prefix='DECRIPTION', length=100)
    url = FuzzyText(prefix='http://WEB-LINK-', suffix='.test', length=10)
    price = FuzzyDecimal(low=1.00)
    shipping_cost = FuzzyDecimal(low=1.00)
    shipping_terms = FuzzyText(prefix='SHIPPING_TERMS', length=100)
    source = FuzzyChoice(choices=[x[1] for x in Product.SOURCES])
    sourcing_date = FuzzyDateTime(start_dt=timezone.now())
    update_date = FuzzyDateTime(start_dt=timezone.now())
    discount = FuzzyDecimal(low=0.00, high=100.00)
    stock = FuzzyInteger(low=0)
    tags = ['test']
    category = FuzzyChoice(choices=FAKE_CATEGORIES) # main tag category
    attributes = ['programming/python', 'testing']
    identifiers = FuzzyText(prefix='IDENTIFIERS_', length=100)

    class Meta:
        model = Product


class ActiveProductFactory(DjangoModelFactory):


    company = SubFactory(CompanyFactory)
    sku = FuzzyText(prefix='SKU_', length=10)
    name = FuzzyText(prefix='NAME_', length=10)
    description = FuzzyText(prefix='DECRIPTION', length=100)
    url = FuzzyText(prefix='http://WEB-LINK-', suffix='.test', length=10)
    price = FuzzyDecimal(low=1.00)
    shipping_cost = FuzzyDecimal(low=1.00)
    shipping_terms = FuzzyText(prefix='SHIPPING_TERMS', length=100)
    source = FuzzyChoice(choices=[x[1] for x in Product.SOURCES])
    sourcing_date = FuzzyDateTime(start_dt=timezone.now())
    update_date = FuzzyDateTime(start_dt=timezone.now())
    discount = FuzzyDecimal(low=0.00, high=100.00)
    stock = FuzzyInteger(low=0)
    tags = ['test']
    category = FuzzyChoice(choices=FAKE_CATEGORIES) # main tag category
    attributes = ['programming/python', 'testing']
    identifiers = FuzzyText(prefix='IDENTIFIERS_', length=100)
    active = True

    class Meta:
        model = Product
