using detect.gui.Models.Entities;
using detect.gui.Services.Detect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Splat;

namespace detect.gui.Api.System;

public class DetectTaskLogApi
{
    public DetectTaskLogApi(IEndpointRouteBuilder? webApp)
    {
        // all
        webApp?.MapGet("/v1/data/task-log/all", () => Locator.Current.GetService<DetectTaskLogService>()!.ListAll());

        // search
        webApp?.MapGet("/v1/data/task-log/search", ([FromQuery] long? taskId, [FromQuery]int pageNum = 1, [FromQuery]int pageSize = 10) => 
        Locator.Current.GetService<DetectTaskLogService>()!.Search(taskId, pageNum, pageSize));
        
        // id
        webApp?.MapGet("/v1/data/task-log/{id:long}", ([FromRoute] long id) => 
            Locator.Current.GetService<DetectTaskLogService>()!.ListById(id));
        
        // add
        webApp?.MapPost("/v1/data/task-log/", ([FromBody] DetectTaskLogEntity entity) => 
            Locator.Current.GetService<DetectTaskLogService>()!.AddData(entity));
        
        // update
        webApp?.MapPut("/v1/data/task-log/", ([FromBody] DetectTaskLogEntity entity) => 
            Locator.Current.GetService<DetectTaskLogService>()!.UpdateData(entity));
            
        // delete
        webApp?.MapDelete("/v1/data/task-log/{id:long}", ([FromRoute] long id) => 
            Locator.Current.GetService<DetectTaskLogService>()!.DeleteById(id));
    }
}