package com.ruoyi.web.modules.store.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.modules.store.dto.SellerShopSwitchDTO;
import com.ruoyi.web.modules.store.service.ISellerShopContextService;

/**
 * 商家端当前店铺上下文（登录后设置 X-Shop-Id）
 */
@RestController
@RequestMapping("/agri/seller/context")
public class SellerShopContextController extends BaseController
{
    @Autowired
    private ISellerShopContextService sellerShopContextService;

    /**
     * 登录后获取当前 shopId（优先当前会话上次所选）；前端写入请求头 X-Shop-Id
     */
    @GetMapping
    public AjaxResult getContext()
    {
        return success(sellerShopContextService.selectContext(getUserId(), getLoginUser().getToken()));
    }

    /**
     * 经营账号切换店铺；前端更新 X-Shop-Id
     */
    @PutMapping("/shop")
    public AjaxResult switchShop(@RequestBody SellerShopSwitchDTO dto)
    {
        return success(sellerShopContextService.switchShop(getUserId(), getLoginUser().getToken(), dto));
    }
}
