import {
    PaginateServicesResults,
    SysAdminPaginateServicesParams,
    SysAdminSetServiceBannedParams,
} from "../../../Models/Services/Service.Interface";
import { ApiValidationError } from "../../../Models/Server.Error.model";
import { ApiVoidResult } from "../../../Models/Api.VoidResult.type";
import { Body, Controller, Middlewares, Post, Response, Route, SuccessResponse } from "tsoa";
import { SA_ServicesService } from "./SysAdminServices.Service";
import { sysAdminAuthMiddleware } from "../../../middleware/sysadminAuth";

@Route("sysadmin/services")
export class SysAdminServicesController extends Controller {
    @Response<ApiValidationError>(500, "Ha ocurrido un error")
    @SuccessResponse(200, "Done")
    @Post("paginate")
    @Middlewares(sysAdminAuthMiddleware)
    public async sysAdminPaginate(
        @Body() requestBody: SysAdminPaginateServicesParams,
    ): Promise<PaginateServicesResults | ApiValidationError> {
        try {
            const { payload, ...cleanRequestBody } = requestBody as any;
            const result = await new SA_ServicesService().sysAdminPaginate(cleanRequestBody);
            this.setStatus(200);
            return result;
        } catch (e) {
            const errorOccurred: Error = e as Error;
            this.setStatus(500);
            return new ApiValidationError(500, errorOccurred.message);
        }
    }

    @Response<ApiValidationError>(500, "Ha ocurrido un error")
    @SuccessResponse(200, "Done")
    @Post("set-banned")
    @Middlewares(sysAdminAuthMiddleware)
    public async sysAdminSetBanned(
        @Body() requestBody: SysAdminSetServiceBannedParams,
    ): Promise<ApiVoidResult | ApiValidationError> {
        try {
            await new SA_ServicesService().sysAdminSetBanned(requestBody);
            this.setStatus(200);
            return { success: true, message: "ok" };
        } catch (e) {
            const errorOccurred: Error = e as Error;
            this.setStatus(500);
            return new ApiValidationError(500, errorOccurred.message);
        }
    }
}
