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 DetectTaskProgressApi
{
    public DetectTaskProgressApi(IEndpointRouteBuilder? webApp)
    {
        // all
        webApp?.MapGet("/v1/data/task-progress/all", () => Locator.Current.GetService<DetectTaskProgressService>()!.ListAll());

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