using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Verification.Commands.ConfirmDocumentUpload;
using Baya.Application.Features.Verification.Commands.RequestDocumentUploadUrl;
using Baya.Application.Features.Verification.Commands.RunBankAccountVerification;
using Baya.Application.Features.Verification.Commands.RunIdentityKyc;
using Baya.Application.Features.Verification.Commands.RunShahkarMatch;
using Baya.Application.Features.Verification.Commands.SubmitCredentialDetails;
using Baya.Application.Features.Verification.Commands.SubmitVerification;
using Baya.Application.Features.Verification.Queries.GetStatus;
using Baya.Application.Models.Verification;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Baya.Web.Api.Controllers.V1;

[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[Display(Description = "The signed-in nurse's verification pipeline (checklist, uploads, automated runs)")]
public sealed class NurseVerificationController(ISender sender) : BaseController
{
    [HttpPost("[action]")]
    [ProducesOkApiResponseType<VerificationStatusDto>]
    public async Task<IActionResult> Submit(CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new SubmitNurseVerificationCommand(), cancellationToken));

    [HttpGet]
    [ProducesOkApiResponseType<VerificationStatusDto>]
    public async Task<IActionResult> Get(CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetNurseVerificationStatusQuery(), cancellationToken));

    [HttpPost("steps/{stepId}/[action]")]
    [ProducesOkApiResponseType<UploadUrlResult>]
    public async Task<IActionResult> UploadUrl(long stepId, RequestDocumentUploadUrlCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command with { StepId = stepId }, cancellationToken));

    [HttpPost("steps/{stepId}/documents")]
    [ProducesOkApiResponseType<DocumentConfirmedResult>]
    public async Task<IActionResult> ConfirmDocument(long stepId, ConfirmDocumentUploadCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command with { StepId = stepId }, cancellationToken));

    // Captures the structured credential fields (INO number, specialties, optional license details) B5
    // collects — the real path used to drop them silently.
    [HttpPost("[action]")]
    [ProducesOkApiResponseType<VerificationStatusDto>]
    public async Task<IActionResult> CredentialDetails(SubmitCredentialDetailsCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));

    [HttpPost("steps/identity_kyc/run")]
    [ProducesOkApiResponseType<RunStepResult>]
    public async Task<IActionResult> RunIdentityKyc(RunIdentityKycCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));

    [HttpPost("steps/shahkar_match/run")]
    [ProducesOkApiResponseType<RunStepResult>]
    public async Task<IActionResult> RunShahkarMatch(CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new RunShahkarMatchCommand(), cancellationToken));

    [HttpPost("steps/bank_account_verification/run")]
    [ProducesOkApiResponseType<RunStepResult>]
    public async Task<IActionResult> RunBankAccountVerification(CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new RunBankAccountVerificationCommand(), cancellationToken));
}
