using Microsoft.EntityFrameworkCore;
using WebApp.DTOs;
using WebApp.Entities;

namespace WebApp.Mapping;

public static class EventMapping
{
    public static Event ToEntity(this EventCreateDto ECDto)
    {
        return new Event()
        {
            Title = ECDto.Title,
            Description = ECDto.Description,
            Location = ECDto.Location,
            EventDate = DateTime.SpecifyKind(ECDto.EventDate!.Value, DateTimeKind.Utc),
            EventSkills = ECDto.EventSkills,
            EventRegistrations = []
        };
    }

    public static Event ToEntity(this EventUpdateDto EUDto, int id)
    {
        return new Event()
        {
            EventId = id,
            Title = EUDto.Title,
            Description = EUDto.Description,
            Location = EUDto.Location,
            EventDate = DateTime.SpecifyKind(EUDto.EventDate!.Value, DateTimeKind.Utc),
            EventSkills = EUDto.EventSkills
        };
    }

    public static EventSummaryDto ToEventSummaryDto(this Event myEvent)
    {
        return new EventSummaryDto(
            myEvent.EventId,
            myEvent.Organisation!.Name,
            myEvent.OrganisationId,
            myEvent.Title,
            myEvent.Description,
            myEvent.Location,
            myEvent.EventDate,
            myEvent.EventSkills,
            myEvent.EventRegistrations
        );
    }
    public static EventSummaryNoErDto ToEventSummaryNoErDto(this Event myEvent)
    {
        return new EventSummaryNoErDto(
            myEvent.EventId,
            myEvent.Organisation!.Name,
            myEvent.OrganisationId,
            myEvent.Title,
            myEvent.Description,
            myEvent.Location,
            myEvent.EventDate,
            myEvent.EventSkills
        );
    }

    public static EventDetailsDto ToEventDetailsDto(this Event myEvent)
    {
        return new EventDetailsDto(
            myEvent.EventId,
            myEvent.OrganisationId,
            myEvent.Organisation.Name,
            myEvent.Title,
            myEvent.Description,
            myEvent.Location,
            myEvent.EventDate,
            myEvent.EventSkills,
            myEvent.EventRegistrations
        );
    }
}