import { PrismaClient } from '@prisma/client'
import { Request, Response, Router } from 'express'
import {{MODEL_NAME}}Controller from './{{MODULE_NAME}}-controller'
import { AppRouter } from '@hive.group/cms'

export default class {{MODEL_NAME}}Router implements AppRouter {
  public readonly router: Router = Router()
  private readonly controller: {{MODEL_NAME}}Controller 

  constructor(public prismaClient: PrismaClient) {
    this.controller = new {{MODEL_NAME}}Controller(prismaClient)
  }

  public index() {
    this.router.get('/', (request: Request, response: Response) => {
      this.controller.index(request, response)
    })
    return this
  }

  public show() {
    this.router.get('/:id', (request: Request, response: Response) => {
      this.controller.show(request, response)
    })
    return this
  }

  public search() {
    this.router.post("/search", (request: Request, response: Response) => {
      this.controller.search(request, response);
    });
    return this;
  }

  public store() {
    this.router.post('/', (request: Request, response: Response) => {
      this.controller.store(request, response)
    })
    return this
  }

  public update() {
    this.router.patch('/:id', (request: Request, response: Response) => {
      this.controller.update(request, response)
    })
    return this
  }
  
  public delete() {
    this.router.delete('/:id', (request: Request, response: Response) => {
      this.controller.destroy(request, response)
    })
    return this
  }
}
