import {ParameterMiddleware, Injectable, Either, ResponseObject, Validator, Valid, right} from '@extollo/lib'
import {ContactForm} from '../../../types/ContactForm.type'

/**
 * ContactForm Middleware
 * --------------------------------------------
 * Parse the contact form data and validate it. Provide the fields as middleware.
 */
@Injectable()
export class ValidContactForm extends ParameterMiddleware<Valid<ContactForm>> {
    async handle(): Promise<Either<ResponseObject, Valid<ContactForm>>> {
        const validator = new Validator<ContactForm>()
        return right(validator.parse(this.request.input()))
    }
}
