from datetime import timedelta

from factory import Sequence
from factory.django import DjangoModelFactory

from django.contrib.auth.models import User
from django.utils.timezone import now
from program.models import (
    FundingCategory,
    Host,
    Image,
    License,
    RRule,
    Schedule,
    Show,
    TimeSlot,
    Type,
)


class CommonUserFactory(DjangoModelFactory):
    class Meta:
        model = User

    password = "password"
    username = Sequence(lambda n: "common_%d" % n)


class HostFactory(DjangoModelFactory):
    class Meta:
        model = Host

    name = Sequence(lambda n: "host %d" % n)


class ImageFactory(DjangoModelFactory):
    class Meta:
        model = Image


class FundingCategoryFactory(DjangoModelFactory):
    class Meta:
        model = FundingCategory

    name = Sequence(lambda n: "funding category %d" % n)
    slug = Sequence(lambda n: "fc_%d" % n)


class TypeFactory(DjangoModelFactory):
    class Meta:
        model = Type

    name = Sequence(lambda n: "type %d" % n)
    slug = Sequence(lambda n: "t_%d" % n)


class ShowFactory(DjangoModelFactory):
    class Meta:
        model = Show

    name = Sequence(lambda n: "show %d" % n)
    slug = Sequence(lambda n: "%s_d" % n)


class RRuleFactory(DjangoModelFactory):
    class Meta:
        model = RRule


class ScheduleFactory(DjangoModelFactory):
    class Meta:
        model = Schedule

    end_time = "03:00:00"
    first_date = "2023-01-01"
    start_time = "02:00:00"


class TimeslotFactory(DjangoModelFactory):
    class Meta:
        model = TimeSlot

    end = now() + timedelta(hours=1)
    start = now()


class LicenseFactory(DjangoModelFactory):
    class Meta:
        model = License

    identifier = "pd"
    name = "Public Domain"