const express = require('express')
const router = express.Router()

const { checkAuthenticated: isLogged, checkNotAuthenticated: isNotLogged } = require('../controller/auth/loggedAuth')
const User = require('../controller/user/user')
const Minute = require('../controller/minutes/minutes')
const Default = require('../controller/minutes/default')
const File = require('../controller/file/file')

//會議記錄
router.get('/minutes/latest', isLogged, Minute.getLatest) //取得最新的會議編號
router
    .route('/minutes')
    .get(Minute.gets)
    .post(
        isLogged,
        File.upload.fields([
            {
                name: 'content',
                maxCount: 1,
            },
            {
                name: 'attach',
                maxCount: 10,
            },
        ]),
        Minute.post
    )

router
    .route('/minutes/:minuteid')
    .all(isLogged)
    .get(Minute.get)
    .put(
        File.upload.fields([
            {
                name: 'content',
                maxCount: 1,
            },
            {
                name: 'attach',
                maxCount: 10,
            },
        ]),
        Minute.put
    )
    .delete(Minute.delete)

//檔案
router.route('/files').get(File.download).delete(isLogged, File.delete)
router.get('/files/folder', File.getFolderFiles)
router.get('/files/zip', File.compress, File.download)
router.get('/files/:minuteid', File.readContent)

//預設值
router.route('/defaults').all(isLogged).get(Default.get).post(Default.post).delete(Default.delete)

//使用者
router.route('/users').all(isLogged).get(User.get).post(User.post)
router.route('/users/:userid').all(isLogged).delete(User.delete).patch(User.update)

module.exports = router
