package com.cool.store.controller.webc;

import com.cool.store.context.PartnerUserHolder;
import com.cool.store.response.HomeTemplateResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.HomeTemplateUserMappingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: WangShuo
 * @Date: 2025/04/08/13:47
 * @Version 1.0
 * @注释:
 */
@RestController
@RequestMapping("/mini/homeTemp")
@Api(value = "小程序首页模板", description = "小程序首页模板")
public class HomeTemplateController {
    @Resource
    private HomeTemplateUserMappingService homeTemplateUserMappingService;

    @ApiOperation("获取用户小程序首页配置")
    @GetMapping("/getUserMiniHomeTemp")
    public ResponseResult<HomeTemplateResponse> getUserMiniHomeTemp() {
        String partnerId = PartnerUserHolder.getUser().getPartnerId();
        return ResponseResult.success(homeTemplateUserMappingService.getHomeTemplateByUserId(partnerId));
    }

    @ApiOperation("保存用户小程序首页配置")
    @PostMapping("/saveUserMiniHomeTemp")
    public ResponseResult<Integer> saveUserMiniHomeTemp(@RequestBody HomeTemplateResponse response){
        return ResponseResult.success(homeTemplateUserMappingService.insertOrUpdateHomeTemplateUserMapping(response,PartnerUserHolder.getUser().getPartnerId()));
    }
}
