from apps.common.seed_media import attach
from apps.services.models import Service

from .content.projects import BODIES
from .content.testimonials import TESTIMONIALS
from .models import Client, Project, Testimonial

# (nom, fichier du logo dans seed_media/clients/)
CLIENTS = [
    *[("Afrikpay", "afrikpay"), ("CCS", "ccs"), ("CEMAC", "cemac"), ("ECN", "ecn")],
    *[("MBM", "mbm"), ("SABC", "sabc"), ("Saham", "saham"), ("SO'BBQ", "sobbq")],
]

# fmt: off
# (slug, titre, secteur, services, résumé, lien)
PROJECTS = [
    ("restaurant-sobbq", "Restaurant SO'BBQ", "Restaurant", ["creation-de-site-web"],
     "Site vitrine du restaurant SO'BBQ.", "http://www.sobarbecue.com"),
    ("rapid-alert-com", "Rapid-Alert.com", "Application web",
     ["sms-mailing-groupes", "applications-web-mobile"],
     "Notre plateforme d'envoi de SMS et d'emails groupés.", "https://rapid-alert.com"),
    ("rapid-invest-com", "Rapid-Invest.com", "", ["applications-web-mobile"],
     "Plateforme web de la famille Rapid.", ""),
    ("neo-industry-s-a", "NEO INDUSTRY S.A.", "", ["creation-de-site-web"],
     "Site institutionnel de NEO INDUSTRY S.A.", "http://www.neoindustrysa.com/"),
    ("rapidticket-cm", "RapidTicket.cm", "", ["applications-web-mobile"],
     "Plateforme de billetterie en ligne.", ""),
]

# fmt: on


def seed() -> None:
    for order, (name, logo) in enumerate(CLIENTS):
        client, _ = Client.objects.update_or_create(name=name, defaults={"order": order})
        attach(client, "logo", f"clients/{logo}.png")
    for order, (slug, title, sector, services, summary, url) in enumerate(PROJECTS):
        project, _ = Project.objects.update_or_create(
            slug=slug,
            defaults={
                "title": title,
                "sector": sector,
                "summary": summary,
                "solution": BODIES[slug],
                "live_url": url,
                "order": order,
                "is_featured": order < 3,
            },
        )
        project.services.set(Service.objects.filter(slug__in=services))
        attach(project, "image", f"projects/{slug}.png")
    for order, (author, role, company, quote) in enumerate(TESTIMONIALS):
        Testimonial.objects.update_or_create(
            author=author, company=company, defaults={"role": role, "quote": quote, "order": order}
        )
