const storeRouter = require("express").Router();
import { Request, Response } from "express";
import getBusinessInformation from "../controllers/store/getBusinessInformation";
import { get } from "mongoose";
import getStoreInformation from "../controllers/store/getStoreInformation";
import postBusinessInformation from "../controllers/store/postBusinessInformation";
import postStoreInformation from "../controllers/store/postStoreInformation";
import getPaymentInformation from "../controllers/store/getPaymentInformation";
import { postPaymentInformation } from "../controllers/store/postPaymentInformation";
import { postStoreLogo } from "../controllers/store/postStoreLogo";
import { imageUpload, handleUploadErrors } from "../middleware/imageUpload";
import { requireAuth } from "../middleware/auth";

storeRouter.get(
  "/api/v1/store/businessInformation/:id",
  requireAuth,
  async (req: Request, res: Response) => {
    getBusinessInformation(req, res);
  }
);

// Public: a vendor's storefront name/logo/description is meant to be
// visible to customers browsing without being logged in.
storeRouter.get(
  "/api/v1/store/storeInformation/:id",
  async (req: Request, res: Response) => {
    getStoreInformation(req, res);
  }
);

storeRouter.get(
  "/api/v1/store/paymentInformation/:id",
  requireAuth,
  async (req: Request, res: Response) => {
    getPaymentInformation(req, res);
  }
);

storeRouter.post(
  "/api/v1/store/paymentInformation",
  requireAuth,
  async (req: Request, res: Response) => {
    postPaymentInformation(req, res);
  }
);

storeRouter.post(
  "/api/v1/store/businessInformation",
  requireAuth,
  async (req: Request, res: Response) => {
    postBusinessInformation(req, res);
  }
);

storeRouter.post(
  "/api/v1/store/storeInformation",
  requireAuth,
  async (req: Request, res: Response) => {
    postStoreInformation(req, res);
  }
);

storeRouter.post(
  "/api/v1/store/logo",
  requireAuth,
  imageUpload.single("file"),
  handleUploadErrors,
  async (req: Request, res: Response) => {
    postStoreLogo(req, res);
  }
);

module.exports = storeRouter;
