import { Router } from 'express';
import { OperationAgentController } from '../controllers/OperationAgentController';
import { Container } from 'typedi';

const router = Router();
const operationAgentController = Container.get(OperationAgentController);

// 绑定店铺
router.post('/stores', (req, res, next) => {
  operationAgentController.bindStore(req.body)
    .then(result => res.json(result))
    .catch(next);
});

// 获取商户的店铺列表
router.get('/stores/:merchantId', (req, res, next) => {
  operationAgentController.getStores(req.params.merchantId)
    .then(result => res.json(result))
    .catch(next);
});

// 获取店铺详情
router.get('/stores/detail/:storeId', (req, res, next) => {
  operationAgentController.getStore(req.params.storeId)
    .then(result => res.json(result))
    .catch(next);
});

// 同步店铺商品
router.post('/stores/:storeId/products/sync', (req, res, next) => {
  operationAgentController.syncProducts(req.params.storeId)
    .then(result => res.json(result))
    .catch(next);
});

// 同步店铺订单
router.post('/stores/:storeId/orders/sync', (req, res, next) => {
  operationAgentController.syncOrders(req.params.storeId)
    .then(result => res.json(result))
    .catch(next);
});

// 更新商品价格
router.put('/stores/:storeId/products/:productId/price', (req, res, next) => {
  operationAgentController.updateProductPrice(req.params.storeId, req.params.productId, req.body.price)
    .then(result => res.json(result))
    .catch(next);
});

// 停用店铺
router.put('/stores/:storeId/deactivate', (req, res, next) => {
  operationAgentController.deactivateStore(req.params.storeId)
    .then(result => res.json(result))
    .catch(next);
});

// 重新激活店铺
router.put('/stores/:storeId/reactivate', (req, res, next) => {
  operationAgentController.reactivateStore(req.params.storeId)
    .then(result => res.json(result))
    .catch(next);
});

export default router;
