using System.ComponentModel; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; namespace LehrerApp.Desktop.Services.Mcp.Tools; /// MCP-Tools "get_time_entries" (Phase 1) und "create_time_entry" (Phase 2), siehe /// Planungsdokument. Der Zeitraum bei "get_time_entries" ist Pflicht (nicht optional), damit eine /// unbedachte Anfrage nicht die gesamte Zeiterfassungshistorie zurückgibt. public class TimeEntryTools(ITimeEntryRepository timeEntries, IGroupRepository groups, IMcpConfirmationService confirmation) { [Description("Listet eigene Zeiterfassungs-Einträge in einem Datumsbereich.")] public List GetTimeEntries( [Description("Startdatum (einschließlich), Format YYYY-MM-DD.")] DateOnly from, [Description("Enddatum (einschließlich), Format YYYY-MM-DD.")] DateOnly to) => timeEntries.GetByDateRange(from, to).Select(t => new TimeEntryDto( t.Id, t.TaskId, t.Category, t.GroupId, t.Date, t.StartTime, t.EndTime, t.DurationMinutes, t.Description)).ToList(); [Description("Schlägt einen neuen Zeiterfassungs-Eintrag vor. Muss der Nutzer erst in einem Dialog in LehrerApp bestätigen, bevor er gespeichert wird.")] public async Task CreateTimeEntry( [Description("Kategorie, z.B. \"Unterricht\", \"Korrektur\", \"Vorbereitung\".")] string category, [Description("Datum, Format YYYY-MM-DD.")] DateOnly date, [Description("Dauer in Minuten.")] int durationMinutes, [Description("Optionale Lerngruppen-ID.")] Guid? groupId = null, [Description("Optionale Beschreibung.")] string? description = null, CancellationToken ct = default) { var groupName = groupId is { } gid ? groups.GetById(gid)?.Name : null; var message = $"Neuer Zeiteintrag: {category}, {durationMinutes} Min. am {date:dd.MM.yyyy}" + (groupName is not null ? $", Gruppe {groupName}" : "") + (string.IsNullOrWhiteSpace(description) ? "" : $"\n„{description}“"); if (!await confirmation.ConfirmAsync("Zeiteintrag anlegen?", message, ct)) return new WriteResultDto(false, null, "Vom Nutzer abgelehnt oder nicht bestätigt."); var entry = new TimeEntry { Category = category, Date = date, DurationMinutes = durationMinutes, GroupId = groupId, Description = description, }; timeEntries.Save(entry); return new WriteResultDto(true, entry.Id, "Zeiteintrag gespeichert."); } }