import PaginationService from 'App/Services/PaginationService'
import FilesRecord from 'App/Models/FilesRecord'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import { schema } from '@ioc:Adonis/Core/Validator'

export default class FilesRecordController {
    private paginationService = new PaginationService(FilesRecord)

    public async index({ request }: HttpContextContract) {
        return await this.paginationService.paginate(request.all())
    }

    public async store({ request, bouncer }: HttpContextContract) {
        await bouncer.authorize('admin')
        await request.validate({
            schema: schema.create({
                deviceId: schema.string(),
                fileUrl: schema.string()
            })
        })
        return await FilesRecord.create(request.all())
    }
}
